Class FlashELResolver
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.
-
Using an Expression Language Expression, such as using
#{flash.foo}as the value of an attribute in a page. -
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"); -
Using getting the
ELFlashdirectly, 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
FlashELResolverELFlash
-
Field Summary
Fields inherited from class jakarta.el.ELResolver
RESOLVABLE_AT_DESIGN_TIME, TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClass<?>getCommonPropertyType(jakarta.el.ELContext context, Object base) Ifbaseis non-nulland is the literal string "flash", returnObject.class.getFeatureDescriptors(jakarta.el.ELContext elContext, Object base) Returns an iterator ofFeatureDescriptorsfor the current contents of the flash.Class<?>Return the validClassfor a future set operation, which will always benullbecause sets happen via theMapELResolveroperating on theELFlashinstance as aMap.Hook into the EL resolution process to introduce theflashimplicit object.booleanisReadOnly(jakarta.el.ELContext elContext, Object base, Object property) Returnstruebecause write operations take place via theMapELResolveron the actualELFlashinstance.voidThis method will throwPropertyNotWritableExceptionif called with anullbaseand apropertyvalue equal to the literal string "flash".Methods inherited from class jakarta.el.ELResolver
convertToType, invoke
-
Constructor Details
-
FlashELResolver
public FlashELResolver()Not intended for manual invocation. Only called by the Faces Runtime.
-
-
Method Details
-
getValue
Hook into the EL resolution process to introduce the
flashimplicit object. Ifpropertyisnull, take no action and returnnull. ifbaseis null, return null. Ifbaseis an instance ofELFlashand 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 theELFlashinstance. Ifbaseis an instance ofELFlashandpropertyis the literal string "now", return the result of callinggetRequestMap( )on theExternalContextfor theFacesContextfor this request. CallsetPropertyResolved(true)on theELContextwhere appropriate.- Specified by:
getValuein classjakarta.el.ELResolver- Throws:
jakarta.el.PropertyNotFoundException- ifpropertyisnull.
-
getType
Return the valid
Classfor a future set operation, which will always benullbecause sets happen via theMapELResolveroperating on theELFlashinstance as aMap.- Specified by:
getTypein classjakarta.el.ELResolver- Throws:
jakarta.el.PropertyNotFoundException- if property isnull.
-
setValue
This method will throw
PropertyNotWritableExceptionif called with anullbaseand apropertyvalue equal to the literal string "flash". This is because set operations normally go through theMapELResolvervia theELFlashMap.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:
setValuein classjakarta.el.ELResolver- Throws:
jakarta.el.PropertyNotFoundException- ifbaseisnullandpropertyisnull.jakarta.el.PropertyNotWritableException- ifbaseisnullandpropertyis the literal string "flash".
-
isReadOnly
Returns
truebecause write operations take place via theMapELResolveron the actualELFlashinstance.- Specified by:
isReadOnlyin classjakarta.el.ELResolver- Throws:
jakarta.el.PropertyNotFoundException- ifbaseisnullandpropertyisnull.
-
getFeatureDescriptors
public Iterator<FeatureDescriptor> getFeatureDescriptors(jakarta.el.ELContext elContext, Object base) Returns an iterator of
FeatureDescriptorsfor the current contents of the flash.- Overrides:
getFeatureDescriptorsin classjakarta.el.ELResolver
-
getCommonPropertyType
If
baseis non-nulland is the literal string "flash", returnObject.class.- Specified by:
getCommonPropertyTypein classjakarta.el.ELResolver
-