org.apache.shale.dialog.base
Class StateSavingListener

java.lang.Object
  extended by org.apache.shale.dialog.base.AbstractDialogContextListener
      extended by org.apache.shale.dialog.base.StateSavingListener
All Implemented Interfaces:
Serializable, DialogContextListener

public class StateSavingListener
extends AbstractDialogContextListener
implements Serializable

Convenience DialogContextListener implementation that supports saving and restoring pre-request state information that is accessed via a configurable set of value binding expressions. Whenever the associated DialogContext is passivated (such as at the end of a request), the getValue() method will be called on each value binding, to save away the retrieved information internally to this instance. Later, when a POST causes our DialogContext instance to be activated again, setValue() will be called on each value binding, to restore the saved data to its original location.

The most common use case for this class will be as the base class for a class that is registered as the data class for a particular dialog. When used in this manner:

So, if you wish to use this mechanism to save and restore the foo and bar request scoped variables, create a subclass like this:

   public class MyStateSavingListener extends StateSavingListener {

     public MyStateSavingListener() {
       setExpressions(new String[] { "#{foo}", "#{bar}" });
     }

   }
 

Next, cause this class to be registered as the standard data class in the configuraiton for this dialog. The details will vary depending on which dialog implementation you are using. Now, the specified state information will be saved and restored for you.

IMPLEMENTATION NOTE - Because this instance will be stored in session scope, all of the data saved via the configured value binding expressions is expected to be serializable.

Since:
1.1.0
See Also:
Serialized Form

Constructor Summary
StateSavingListener()
           
 
Method Summary
 String[] getExpressions()
          Return an array of value binding expressions that identify state information to be saved and restored.
 void onActivate()
          Restore the values specified by our configured expressions.
 void onPassivate()
          Save the values specified by our configured expressions.
 void setExpressions(String[] expressions)
          Set the array of value binding expressions that identify state information to be saved and restored.
 
Methods inherited from class org.apache.shale.dialog.base.AbstractDialogContextListener
getDialogContext, onEntry, onException, onExit, onStart, onStop, onTransition, setDialogContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateSavingListener

public StateSavingListener()
Method Detail

getExpressions

public String[] getExpressions()

Return an array of value binding expressions that identify state information to be saved and restored.


setExpressions

public void setExpressions(String[] expressions)

Set the array of value binding expressions that identify state information to be saved and restored.

Parameters:
expressions - The new expressions

onActivate

public void onActivate()

Restore the values specified by our configured expressions.

Specified by:
onActivate in interface DialogContextListener
Overrides:
onActivate in class AbstractDialogContextListener
See Also:
DialogContextListener.onActivate()

onPassivate

public void onPassivate()

Save the values specified by our configured expressions.

Specified by:
onPassivate in interface DialogContextListener
Overrides:
onPassivate in class AbstractDialogContextListener
See Also:
DialogContextListener.onPassivate()


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.