Top Description Fields Constructors Methods
com.sun.faces.context.flash

public Class FlashELResolver

extends ELResolver
Class Inheritance
Imports
jakarta.el.ELContext, .ELResolver, .PropertyNotFoundException, .PropertyNotWritableException, jakarta.faces.FactoryFinder, jakarta.faces.context.ExternalContext, .FacesContext, .Flash, .FlashFactory, java.util.Map

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

Modifier and TypeField and Description
private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
FlashELResolver()

Not intended for manual invocation.

Method Summary

Modifier and TypeMethod and Description
public Class<?>
getCommonPropertyType(ELContext
The context of this evaluation.
context
,
Object
The base object to return the most general property type for, or null to enumerate the set of top-level variables that this resolver can evaluate.
base
)

Implements abstract jakarta.el.ELResolver.getCommonPropertyType.

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

public Class<?>
getType(ELContext
The context of this evaluation.
elContext
,
Object
The base object whose property value is to be analyzed, or null to analyze a top-level variable.
base
,
Object
The property or variable to return the acceptable type for.
property
)

Implements abstract jakarta.el.ELResolver.getType.

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.

public Object
getValue(ELContext
The context of this evaluation.
elContext
,
Object
The base object whose property value is to be returned, or null to resolve a top-level variable.
base
,
Object
The property or variable to be resolved.
property
)

Implements abstract jakarta.el.ELResolver.getValue.

Hook into the EL resolution process to introduce the flash implicit object.

public boolean
isReadOnly(ELContext
The context of this evaluation.
elContext
,
Object
The base object whose property value is to be analyzed, or null to analyze a top-level variable.
base
,
Object
The property or variable to return the read-only status for.
property
)

Implements abstract jakarta.el.ELResolver.isReadOnly.

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

public void
setValue(ELContext
The context of this evaluation.
elContext
,
Object
The base object whose property value is to be set, or null to set a top-level variable.
base
,
Object
The property or variable to be set.
property
,
Object
The value to set the property or variable to.
value
)

Implements abstract jakarta.el.ELResolver.setValue.

This method will throw PropertyNotWritableException if called with a null base and a property value equal to the literal string "flash".

Inherited from jakarta.el.ELResolver:
convertToTypeinvoke

Field Detail

FLASH_KEEP_VARIABLE_NAMEback to summary
private static final String FLASH_KEEP_VARIABLE_NAME
FLASH_NOW_VARIABLE_NAMEback to summary
private static final String FLASH_NOW_VARIABLE_NAME
FLASH_VARIABLE_NAMEback to summary
private static final String FLASH_VARIABLE_NAME

Constructor Detail

FlashELResolverback to summary
public FlashELResolver()

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

Method Detail

getCommonPropertyTypeback to summary
public Class<?> getCommonPropertyType(ELContext context, Object base)

Implements abstract jakarta.el.ELResolver.getCommonPropertyType.

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

Parameters
context:ELContext

Doc from jakarta.el.ELResolver.getCommonPropertyType.

The context of this evaluation.

base:Object

Doc from jakarta.el.ELResolver.getCommonPropertyType.

The base object to return the most general property type for, or null to enumerate the set of top-level variables that this resolver can evaluate.

Returns:Class<?>

Doc from jakarta.el.ELResolver.getCommonPropertyType.

null if this ELResolver does not know how to handle the given base object; otherwise Object.class if any type of property is accepted; otherwise the most general property type accepted for the given base.

Annotations
@Override
getTypeback to summary
public Class<?> getType(ELContext elContext, Object base, Object property)

Implements abstract jakarta.el.ELResolver.getType.

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.

Parameters
elContext:ELContext

Doc from jakarta.el.ELResolver.getType.

The context of this evaluation.

base:Object

Doc from jakarta.el.ELResolver.getType.

The base object whose property value is to be analyzed, or null to analyze a top-level variable.

property:Object

Doc from jakarta.el.ELResolver.getType.

The property or variable to return the acceptable type for.

Returns:Class<?>

Doc from jakarta.el.ELResolver.getType.

If the propertyResolved property of ELContext was set to true, the most general acceptable type which must be null if the either the property or the resolver is read-only; otherwise undefined

Annotations
@Override
Exceptions
PropertyNotFoundException:
if property is null.
getValueback to summary
public Object getValue(ELContext elContext, Object base, Object property)

Implements abstract jakarta.el.ELResolver.getValue.

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.

Parameters
elContext:ELContext

Doc from jakarta.el.ELResolver.getValue.

The context of this evaluation.

base:Object

Doc from jakarta.el.ELResolver.getValue.

The base object whose property value is to be returned, or null to resolve a top-level variable.

property:Object

Doc from jakarta.el.ELResolver.getValue.

The property or variable to be resolved.

Returns:Object

Doc from jakarta.el.ELResolver.getValue.

If the propertyResolved property of ELContext was set to true, then the result of the variable or property resolution; otherwise undefined.

Annotations
@Override
Exceptions
PropertyNotFoundException:
if property is null.
isReadOnlyback to summary
public boolean isReadOnly(ELContext elContext, Object base, Object property)

Implements abstract jakarta.el.ELResolver.isReadOnly.

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

Parameters
elContext:ELContext

Doc from jakarta.el.ELResolver.isReadOnly.

The context of this evaluation.

base:Object

Doc from jakarta.el.ELResolver.isReadOnly.

The base object whose property value is to be analyzed, or null to analyze a top-level variable.

property:Object

Doc from jakarta.el.ELResolver.isReadOnly.

The property or variable to return the read-only status for.

Returns:boolean

Doc from jakarta.el.ELResolver.isReadOnly.

If the propertyResolved property of ELContext was set to true, then true if the property is read-only or false if not; otherwise undefined.

Annotations
@Override
Exceptions
PropertyNotFoundException:
if base is null and property is null.
setValueback to summary
public void setValue(ELContext elContext, Object base, Object property, Object value)

Implements abstract jakarta.el.ELResolver.setValue.

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.

Parameters
elContext:ELContext

Doc from jakarta.el.ELResolver.setValue.

The context of this evaluation.

base:Object

Doc from jakarta.el.ELResolver.setValue.

The base object whose property value is to be set, or null to set a top-level variable.

property:Object

Doc from jakarta.el.ELResolver.setValue.

The property or variable to be set.

value:Object

Doc from jakarta.el.ELResolver.setValue.

The value to set the property or variable to.

Annotations
@Override
Exceptions
PropertyNotFoundException:
if base is null and property is null.
PropertyNotWritableException:
if base is null and property is the literal string "flash".