Class FlashELResolver

java.lang.Object
jakarta.el.ELResolver
com.sun.faces.context.flash.FlashELResolver

public class FlashELResolver extends jakarta.el.ELResolver

Provide a feature semantically identical to the "flash" concept in Ruby on Rails.

The feature is exposed to users via a custom ELResolver which introduces a new implicit object, flash. The flash functions as Map and can be used in getValue( ) or setValue( ) expressions.

Usage

Consider three Faces views: viewA, viewB, and viewC. The user first views viewA, then clicks a button and is shown viewB, where she clicks a button and is shown viewC. If values are stored into the flash during the rendering or postback phases of viewA, they are available to during the rendering phase of viewB, but are not available during the rendering or postback phases of viewC. In other words, values stored into the flash on "this" request are accessible for the "next" request, but not thereafter.

There are three ways to access the flash.

  1. Using an Expression Language Expression, such as using #{flash.foo} as the value of an attribute in a page.
  2. Using the EL API, such as:

    FacesContext context = FacesContext.getCurrentInstance(); ValueExpression flashExpression = context.getApplication(). createValueExpression(context.getELContext(), "#{flash.foo}", null, Object.class); flashExpression.setValue(context.getELContext(), "Foo's new value");

  3. Using getting the ELFlash directly, such as:

    Map<String,Object> flash = ELFlash.getFlash(); flash.put("foo", "Foo's new value");

The main entry point to this feature is the first one. This library includes a simple custom tag, jsfExt:set, that evaluates an expression and sets its value into another expression. jsfExt:set can be used to store values into the flash from JSP pages, like this:

<jsfExt:set var="#{flash.foo}" value="fooValue" />

or this:

<jsfExt:set var="#{flash.keep.bar}" value="#{user.name}" />

or even this:

<jsfExt:set var="#{flash.now.baz}" value="#{cookie.userCookie}" /> <h:outputText value="#{flash.now.baz}" />

Related Classes

The complete list of classes that make up this feature is

  • Field Summary

    Fields inherited from class jakarta.el.ELResolver

    RESOLVABLE_AT_DESIGN_TIME, TYPE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Not intended for manual invocation.
  • Method Summary

    Modifier and Type
    Method
    Description
    getCommonPropertyType(jakarta.el.ELContext context, Object base)
    If base is non-null and is the literal string "flash", return Object.class.
    getFeatureDescriptors(jakarta.el.ELContext elContext, Object base)
    Returns an iterator of FeatureDescriptors for the current contents of the flash.
    getType(jakarta.el.ELContext elContext, Object base, Object property)
    Return the valid Class for a future set operation, which will always be null because sets happen via the MapELResolver operating on the ELFlash instance as a Map.
    getValue(jakarta.el.ELContext elContext, Object base, Object property)
    Hook into the EL resolution process to introduce the flash implicit object.
    boolean
    isReadOnly(jakarta.el.ELContext elContext, Object base, Object property)
    Returns true because write operations take place via the MapELResolver on the actual ELFlash instance.
    void
    setValue(jakarta.el.ELContext elContext, Object base, Object property, Object value)
    This method will throw PropertyNotWritableException if called with a null base and a property value equal to the literal string "flash".

    Methods inherited from class jakarta.el.ELResolver

    convertToType, invoke

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FlashELResolver

      public FlashELResolver()

      Not intended for manual invocation. Only called by the Faces Runtime.

  • Method Details

    • getValue

      public Object getValue(jakarta.el.ELContext elContext, Object base, Object property)

      Hook into the EL resolution process to introduce the flash implicit object. If property is null, take no action and return null. if base is null, return null. If base is an instance of ELFlash and property is the literal string "keep", set a ThreadLocal property that will be inspected by the flash on the next link in the resolution chain and return the ELFlash instance. If base is an instance of ELFlash and property is the literal string "now", return the result of calling getRequestMap( ) on the ExternalContext for the FacesContext for this request. Call setPropertyResolved(true) on the ELContext where appropriate.

      Specified by:
      getValue in class jakarta.el.ELResolver
      Throws:
      jakarta.el.PropertyNotFoundException - if property is null.
    • getType

      public Class<?> getType(jakarta.el.ELContext elContext, Object base, Object property)

      Return the valid Class for a future set operation, which will always be null because sets happen via the MapELResolver operating on the ELFlash instance as a Map.

      Specified by:
      getType in class jakarta.el.ELResolver
      Throws:
      jakarta.el.PropertyNotFoundException - if property is null.
    • setValue

      public void setValue(jakarta.el.ELContext elContext, Object base, Object property, Object value)

      This method will throw PropertyNotWritableException if called with a null base and a property value equal to the literal string "flash". This is because set operations normally go through the MapELResolver via the ELFlash Map.

      In other words, do not call this method directly to set a value into the flash! The only way to access the flash is via the EL API.

      Specified by:
      setValue in class jakarta.el.ELResolver
      Throws:
      jakarta.el.PropertyNotFoundException - if base is null and property is null.
      jakarta.el.PropertyNotWritableException - if base is null and property is the literal string "flash".
    • isReadOnly

      public boolean isReadOnly(jakarta.el.ELContext elContext, Object base, Object property)

      Returns true because write operations take place via the MapELResolver on the actual ELFlash instance.

      Specified by:
      isReadOnly in class jakarta.el.ELResolver
      Throws:
      jakarta.el.PropertyNotFoundException - if base is null and property is null.
    • getFeatureDescriptors

      public Iterator<FeatureDescriptor> getFeatureDescriptors(jakarta.el.ELContext elContext, Object base)

      Returns an iterator of FeatureDescriptors for the current contents of the flash.

      Overrides:
      getFeatureDescriptors in class jakarta.el.ELResolver
    • getCommonPropertyType

      public Class<?> getCommonPropertyType(jakarta.el.ELContext context, Object base)

      If base is non-null and is the literal string "flash", return Object.class.

      Specified by:
      getCommonPropertyType in class jakarta.el.ELResolver