javax.faces.application
Class StateManager

java.lang.Object
  extended by javax.faces.application.StateManager

public abstract class StateManager
extends Object

Responsible for storing sufficient information about a component tree so that an identical tree can later be recreated.

It is up to the concrete implementation to decide whether to use information from the "view template" that was used to first create the view, or whether to store sufficient information to enable the view to be restored without any reference to the original template. However as JSF components have mutable fields that can be set by code, and affected by user input, at least some state does need to be kept in order to recreate a previously-existing component tree.

There are two different options defined by the specification: "client" and "server" state.

When "client" state is configured, all state information required to create the tree is embedded within the data rendered to the client. Note that because data received from a remote client must always be treated as "tainted", care must be taken when using such data. Some StateManager implementations may use encryption to ensure that clients cannot modify the data, and that the data received on postback is therefore trustworthy.

When "server" state is configured, the data is saved somewhere "on the back end", and (at most) a token is embedded in the data rendered to the user.

This class is usually invoked by a concrete implementation of ViewHandler.

Note that class ViewHandler isolates JSF components from the details of the request format. This class isolates JSF components from the details of the response format. Because request and response are usually tightly coupled, the StateManager and ViewHandler implementations are also usually fairly tightly coupled (ie the ViewHandler/StateManager implementations come as pairs).

See the javadoc for this class in the JSF Specification for more details.

Version:
$Revision: 705327 $ $Date: 2008-10-16 14:06:57 -0500 (Thu, 16 Oct 2008) $
Author:
Manfred Geiler (latest modification by $Author: skitching $)

Nested Class Summary
 class StateManager.SerializedView
           
 
Field Summary
static String STATE_SAVING_METHOD_CLIENT
           
static String STATE_SAVING_METHOD_PARAM_NAME
           
static String STATE_SAVING_METHOD_SERVER
           
 
Constructor Summary
StateManager()
           
 
Method Summary
protected abstract  Object getComponentStateToSave(FacesContext context)
          Return data that can be applied to a component tree created using the "getTreeStructureToSave" method.
protected abstract  Object getTreeStructureToSave(FacesContext context)
          Return data that is sufficient to recreate the component tree that is the viewroot of the specified context, but without restoring the state in the components.
 boolean isSavingStateInClient(FacesContext context)
           
protected abstract  void restoreComponentState(FacesContext context, UIViewRoot viewRoot, String renderKitId)
           
protected abstract  UIViewRoot restoreTreeStructure(FacesContext context, String viewId, String renderKitId)
           
abstract  UIViewRoot restoreView(FacesContext context, String viewId, String renderKitId)
           
abstract  StateManager.SerializedView saveSerializedView(FacesContext context)
          Invokes getTreeStructureToSave and getComponentStateToSave, then return an object that wraps the two resulting objects.
abstract  void writeState(FacesContext context, StateManager.SerializedView state)
          Associate the provided state object with the current response being generated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_SAVING_METHOD_PARAM_NAME

public static final String STATE_SAVING_METHOD_PARAM_NAME
See Also:
Constant Field Values

STATE_SAVING_METHOD_CLIENT

public static final String STATE_SAVING_METHOD_CLIENT
See Also:
Constant Field Values

STATE_SAVING_METHOD_SERVER

public static final String STATE_SAVING_METHOD_SERVER
See Also:
Constant Field Values
Constructor Detail

StateManager

public StateManager()
Method Detail

saveSerializedView

public abstract StateManager.SerializedView saveSerializedView(FacesContext context)
Invokes getTreeStructureToSave and getComponentStateToSave, then return an object that wraps the two resulting objects. This object can then be passed to method writeState.


getTreeStructureToSave

protected abstract Object getTreeStructureToSave(FacesContext context)
Return data that is sufficient to recreate the component tree that is the viewroot of the specified context, but without restoring the state in the components.

Using this data, a tree of components which has the same "shape" as the original component tree can be recreated. However the component instances themselves will have only their default values, ie their member fields will not have been set to the original values.


getComponentStateToSave

protected abstract Object getComponentStateToSave(FacesContext context)
Return data that can be applied to a component tree created using the "getTreeStructureToSave" method.


writeState

public abstract void writeState(FacesContext context,
                                StateManager.SerializedView state)
                         throws IOException
Associate the provided state object with the current response being generated.

When client-side state is enabled, it is expected that method writes the data contained in the state parameter to the response somehow.

When server-side state is enabled, at most a "token" is expected to be written.

Throws:
IOException

restoreView

public abstract UIViewRoot restoreView(FacesContext context,
                                       String viewId,
                                       String renderKitId)

restoreTreeStructure

protected abstract UIViewRoot restoreTreeStructure(FacesContext context,
                                                   String viewId,
                                                   String renderKitId)

restoreComponentState

protected abstract void restoreComponentState(FacesContext context,
                                              UIViewRoot viewRoot,
                                              String renderKitId)

isSavingStateInClient

public boolean isSavingStateInClient(FacesContext context)


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.