org.apache.click.util
Class FlashAttribute

java.lang.Object
  extended by org.apache.click.util.FlashAttribute
All Implemented Interfaces:
Serializable

public class FlashAttribute
extends Object
implements Serializable

Provides a flash session attribute. The flash attribute simply wraps an existing session attribute providing a marker to the Context and SessionMap classes that the session attribute should be removed once it has been accessed.

Flash session attributes appear only once in a session, after they have been accessed they are removed from the session. Flash attributes are typically used for display information messages to a user, and can be used with page redirects.

Note you generally do not use FlashAttribute directly, but indirectly via the Context setFlashAttribute() method. For example:

 public boolean onOkClick() {
     // Perform logic
     ..
     String message = "Operation successfully completed";

     getContext().setFlashAttribute("message", message);
     setRedirect(HomePage.class);
     return false;
 }
 
To test for the existence of a flash attribute and then render it, you should set it as a variable in your template, because once it has been accessed from the session it is removed. Using Velocity as an example:
 #set ($message = $session.message)
 #if ($message)
   <p>$message</p>
 #end 

See Also:
Context, SessionMap, Serialized Form

Field Summary
protected  Object value
          The session attribute value.
 
Constructor Summary
FlashAttribute(Object value)
          Create a session flash attribute with the given value.
 
Method Summary
 Object getValue()
          Return the flash session attribute value.
 String toString()
          Return the string representation of the flash attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

protected Object value
The session attribute value.

Constructor Detail

FlashAttribute

public FlashAttribute(Object value)
Create a session flash attribute with the given value.

Parameters:
value - the flash session attribute value
Method Detail

getValue

public Object getValue()
Return the flash session attribute value.

Returns:
the flash session attribute value

toString

public String toString()
Return the string representation of the flash attribute.

Overrides:
toString in class Object
Returns:
the string representation of the flash attribute
See Also:
Object.toString()