JSF-Spring

de.mindmatters.faces.application
Class OptimizedStateManager

java.lang.Object
  extended by javax.faces.application.StateManager
      extended by de.mindmatters.faces.application.OptimizedStateManager

public final class OptimizedStateManager
extends StateManager

OptimizedStateManager directs the process of saving and restoring the view between requests.

This state manager only works with a view handler of type ViewBuilder! Because an implemention of a ViewBuilder is able to restore the structure of a component tree of a view without a given serialized state this state manager writes no component structure state. This class restores the component tree by invoking the method ViewBuilder.buildView(FacesContext, String) of the configured view handler.

Author:
Andreas Kuhrwahl
See Also:
ViewBuilder.buildView(FacesContext, String)

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.faces.application.StateManager
StateManager.SerializedView
 
Field Summary
 
Fields inherited from class javax.faces.application.StateManager
STATE_SAVING_METHOD_CLIENT, STATE_SAVING_METHOD_PARAM_NAME, STATE_SAVING_METHOD_SERVER
 
Constructor Summary
OptimizedStateManager(StateManager delegate)
          Creates an OptimizedStateManager with the given state manager delegate of the underlying JSF implementation.
 
Method Summary
protected  java.lang.Object getComponentStateToSave(FacesContext context)
          

Convenience method, which must be called by saveSerializedView(), to construct and return a Serializable object that represents the state of all component properties, attributes, and attached objects, for the entire component tree (including children and facets) of this view.

protected  java.lang.Object getTreeStructureToSave(FacesContext context)
          

Convenience method, which must be called by saveSerializedView(), to construct and return a Serializable object that represents the structure of the entire component tree (including children and facets) of this view.

protected  void restoreComponentState(FacesContext context, UIViewRoot viewRoot, java.lang.String renderKitId)
          

Convenience method, which must be called by restoreView(), to restore the attributes, properties, and attached objects of all components in the restored component tree.

protected  UIViewRoot restoreTreeStructure(FacesContext context, java.lang.String viewId, java.lang.String renderKitId)
          

Convenience method, which must be called by restoreView(), to construct and return a UIViewRoot instance (populated with children and facets) representing the tree structure of the component tree being restored.

 UIViewRoot restoreView(FacesContext context, java.lang.String viewId, java.lang.String renderKitId)
          

Restore the tree structure and the component state of the view for the specified viewId, in an implementation dependent manner, and return the restored UIViewRoot.

 StateManager.SerializedView saveSerializedView(FacesContext context)
          

Return the tree structure and component state information for the view contained in the specified FacesContext instance as an object of type StateManager.SerializedView.

 void writeState(FacesContext context, StateManager.SerializedView state)
          

Save the state represented in the specified SerializedView isntance, in an implementation dependent manner.

 
Methods inherited from class javax.faces.application.StateManager
isSavingStateInClient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptimizedStateManager

public OptimizedStateManager(StateManager delegate)
Creates an OptimizedStateManager with the given state manager delegate of the underlying JSF implementation.

Parameters:
delegate - the original state manager of the underlying JSF implementation
Method Detail

saveSerializedView

public StateManager.SerializedView saveSerializedView(FacesContext context)

Return the tree structure and component state information for the view contained in the specified FacesContext instance as an object of type StateManager.SerializedView. If there is no state information to be saved, return null instead.

Components may opt out of being included in the serialized view by setting their transient property to true. This must cause the component itself, as well as all of that component's children and facets, to be omitted from the saved tree structure and component state information.

This method must also enforce the rule that, for components with non-null ids, all components that are descendants of the same nearest NamingContainer must have unique identifiers.

Specified by:
saveSerializedView in class StateManager
Parameters:
context - FacesContext for the current request

getTreeStructureToSave

protected java.lang.Object getTreeStructureToSave(FacesContext context)

Convenience method, which must be called by saveSerializedView(), to construct and return a Serializable object that represents the structure of the entire component tree (including children and facets) of this view.

Components may opt-out of being included in the tree structure by setting their transient property to true. This must cause the component itself, as well as all of that component's children and facets, to be omitted from the saved tree structure information.

PENDING(craigmcc) - Does this method need to be in the public APIs?

Specified by:
getTreeStructureToSave in class StateManager
Parameters:
context - FacesContext for the current request

getComponentStateToSave

protected java.lang.Object getComponentStateToSave(FacesContext context)

Convenience method, which must be called by saveSerializedView(), to construct and return a Serializable object that represents the state of all component properties, attributes, and attached objects, for the entire component tree (including children and facets) of this view.

Components may opt-out of being included in the component state by setting their transient property to true. This must cause the component itself, as well as all of that component's children and facets, to be omitted from the saved component state information.

PENDING(craigmcc) - Does this method need to be in the public APIs?

Specified by:
getComponentStateToSave in class StateManager
Parameters:
context - FacesContext for the current request

writeState

public void writeState(FacesContext context,
                       StateManager.SerializedView state)
                throws java.io.IOException

Save the state represented in the specified SerializedView isntance, in an implementation dependent manner.

This method must consult the context initialization parameter named by the symbolic constant StateManager.STATE_SAVING_METHOD_PARAMETER_NAME to determine whether state should be saved on the client or the server. If not present, client side state saving is assumed.

If the init parameter indicates that client side state saving should be used, this method must delegate the actual writing to the writeState() method of the ResponseStateManager instance provided by the RenderKit being used to render this view. This method assumes that the caller has positioned the ResponseWriter at the correct position for the saved state to be written.

If the init parameter indicates that server side state saving should be used, this method must save the state in such a manner that it may be retrieved using only the viewId.

Specified by:
writeState in class StateManager
Parameters:
context - FacesContext for the current request
state - the serialized state to be written
Throws:
java.io.IOException

restoreView

public UIViewRoot restoreView(FacesContext context,
                              java.lang.String viewId,
                              java.lang.String renderKitId)

Restore the tree structure and the component state of the view for the specified viewId, in an implementation dependent manner, and return the restored UIViewRoot. If there is no saved state information available for this viewId, return null instead.

This method must consult the context initialization parameter named by the symbolic constant StateManager.STATE_SAVING_METHOD_PARAMETER_NAME to determine whether state should be saved on the client or the server. If not present, client side state saving is assumed.

If the init parameter indicates that client side state saving should be used, this method must call the getTreeStructureToRestore() and (if the previous method call returned a non-null value) getComponentStateToRestore() methods of the ResponseStateManager instance provided by the RenderKit responsible for this view.

Specified by:
restoreView in class StateManager
Parameters:
context - FacesContext for the current request
viewId - View identifier of the view to be restored
renderKitId - the renderKitId used to render this response. Must not be null.

restoreTreeStructure

protected UIViewRoot restoreTreeStructure(FacesContext context,
                                          java.lang.String viewId,
                                          java.lang.String renderKitId)

Convenience method, which must be called by restoreView(), to construct and return a UIViewRoot instance (populated with children and facets) representing the tree structure of the component tree being restored. If no saved state information is available, return null instead.

PENDING(craigmcc) - Does this method need to be in the public APIs?

Specified by:
restoreTreeStructure in class StateManager
Parameters:
context - FacesContext for the current request
viewId - View identifier of the view to be restored
renderKitId - the renderKitId used to render this response. Must not be null.

restoreComponentState

protected void restoreComponentState(FacesContext context,
                                     UIViewRoot viewRoot,
                                     java.lang.String renderKitId)

Convenience method, which must be called by restoreView(), to restore the attributes, properties, and attached objects of all components in the restored component tree.

PENDING(craigmcc) - Does this method need to be in the public APIs?

Specified by:
restoreComponentState in class StateManager
Parameters:
context - FacesContext for the current request
viewRoot - UIViewRoot returned by a previous call to restoreTreeStructure()
renderKitId - the renderKitId used to render this response. Must not be null.

JSF-Spring

Copyright © 2006 mindmatters GmbH & Co. KG