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
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
FlashELResolver
ELFlash
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionClass
<?> getCommonPropertyType
(ELContext context, Object base) Ifbase
is non-null
and is the literal string "flash", returnObject.class
.Class
<?> Return the validClass
for a future set operation, which will always benull
because sets happen via theMapELResolver
operating on theELFlash
instance as aMap
.Hook into the EL resolution process to introduce theflash
implicit object.boolean
isReadOnly
(ELContext elContext, Object base, Object property) Returnstrue
because write operations take place via theMapELResolver
on the actualELFlash
instance.void
This method will throwPropertyNotWritableException
if called with anull
base
and aproperty
value 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
flash
implicit object. Ifproperty
isnull
, take no action and returnnull
. ifbase
is null, return null. Ifbase
is an instance ofELFlash
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 theELFlash
instance. Ifbase
is an instance ofELFlash
andproperty
is the literal string "now", return the result of callinggetRequestMap( )
on theExternalContext
for theFacesContext
for this request. CallsetPropertyResolved(true)
on theELContext
where appropriate.- Specified by:
getValue
in classELResolver
- Parameters:
elContext
- The context of this evaluation.base
- The base object whose property value is to be returned, ornull
to resolve a top-level variable.property
- The property or variable to be resolved.- Returns:
- If the
propertyResolved
property ofELContext
was set totrue
, then the result of the variable or property resolution; otherwise undefined. - Throws:
PropertyNotFoundException
- ifproperty
isnull
.
-
getType
Return the valid
Class
for a future set operation, which will always benull
because sets happen via theMapELResolver
operating on theELFlash
instance as aMap
.- Specified by:
getType
in classELResolver
- Parameters:
elContext
- The context of this evaluation.base
- The base object whose property value is to be analyzed, ornull
to analyze a top-level variable.property
- The property or variable to return the acceptable type for.- Returns:
- If the
propertyResolved
property ofELContext
was set totrue
, the most general acceptable type which must benull
if the either the property or the resolver is read-only; otherwise undefined - Throws:
PropertyNotFoundException
- if property isnull
.
-
setValue
This method will throw
PropertyNotWritableException
if called with anull
base
and aproperty
value equal to the literal string "flash". This is because set operations normally go through theMapELResolver
via theELFlash
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 classELResolver
- Parameters:
elContext
- The context of this evaluation.base
- The base object whose property value is to be set, ornull
to set a top-level variable.property
- The property or variable to be set.value
- The value to set the property or variable to.- Throws:
PropertyNotFoundException
- ifbase
isnull
andproperty
isnull
.PropertyNotWritableException
- ifbase
isnull
andproperty
is the literal string "flash".
-
isReadOnly
Returns
true
because write operations take place via theMapELResolver
on the actualELFlash
instance.- Specified by:
isReadOnly
in classELResolver
- Parameters:
elContext
- The context of this evaluation.base
- The base object whose property value is to be analyzed, ornull
to analyze a top-level variable.property
- The property or variable to return the read-only status for.- Returns:
- If the
propertyResolved
property ofELContext
was set totrue
, thentrue
if the property is read-only orfalse
if not; otherwise undefined. - Throws:
PropertyNotFoundException
- ifbase
isnull
andproperty
isnull
.
-
getCommonPropertyType
If
base
is non-null
and is the literal string "flash", returnObject.class
.- Specified by:
getCommonPropertyType
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- The base object to return the most general property type for, ornull
to enumerate the set of top-level variables that this resolver can evaluate.- Returns:
null
if thisELResolver
does not know how to handle the givenbase
object; otherwiseObject.class
if any type ofproperty
is accepted; otherwise the most generalproperty
type accepted for the givenbase
.
-