Class StateManager
- Direct Known Subclasses:
StateManagerWrapper
StateManager directs the process of saving and restoring the view between requests.
An implementation of this class must be thread-safe. The StateManager
instance for an application is retrieved from the Application instance, and thus cannot know any details of
the markup language created by the RenderKit being used to render a view.
The StateManager utilizes a helper object (ResponseStateManager), that is provided by the
RenderKit implementation and is therefore aware of the markup language details.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe runtime must interpret the value of this parameter as a comma separated list of view IDs, each of which must have their state saved using the state saving mechanism specified in Jakarta Server Faces 1.2.static final StringMarker within theFacesContextattributes map to indicate we are marking initial state, so themarkInitialState()method of iterating components such asUIDatacould recognize this fact and save the initial state of descendents.static final StringMarker within theFacesContextattributes map to indicate we are saving state.static final StringTheServletContextinit parameter consulted by the runtime to determine if the partial state saving mechanism should be used.static final StringIf this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true, and the jakarta.faces.STATE_SAVING_METHOD is set to "server" (as indicated below), the server state must be guaranteed to be Serializable such that the aggregate state implements java.io.Serializable.static final StringConstant value for the initialization parameter named by theSTATE_SAVING_METHOD_PARAM_NAMEthat indicates state saving should take place on the client.static final StringTheServletContextinit parameter consulted by theStateManagerto tell where the state should be saved.static final StringConstant value for the initialization parameter named by theSTATE_SAVING_METHOD_PARAM_NAMEthat indicates state saving should take place on the server. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectgetComponentStateToSave(FacesContext context) Deprecated.the distinction between tree structure and component state is now an implementation detail.protected ObjectgetTreeStructureToSave(FacesContext context) Deprecated.the distinction between tree structure and component state is now an implementation detail.getViewState(FacesContext context) Convenience method to return the view state as aStringwith noRenderKitspecific markup.booleanisSavingStateInClient(FacesContext context) Method to determine if the state is saved on the client.protected voidrestoreComponentState(FacesContext context, UIViewRoot viewRoot, String renderKitId) Deprecated.the distinction between tree structure and component state is now an implementation detail.protected UIViewRootrestoreTreeStructure(FacesContext context, String viewId, String renderKitId) Deprecated.the distinction between tree structure and component state is now an implementation detail.abstract UIViewRootrestoreView(FacesContext context, String viewId, String renderKitId) Deprecated.saveSerializedView(FacesContext context) Deprecated.this has been replaced bysaveView(jakarta.faces.context.FacesContext).saveView(FacesContext context) Deprecated.voidwriteState(FacesContext context, StateManager.SerializedView state) Deprecated.This method has been replaced bywriteState(jakarta.faces.context.FacesContext,java.lang.Object).voidwriteState(FacesContext context, Object state) Save the state represented in the specified stateObjectinstance, in an implementation dependent manner.
-
Field Details
-
STATE_SAVING_METHOD_PARAM_NAME
The
ServletContextinit parameter consulted by theStateManagerto tell where the state should be saved. Valid values are given as the values of the constants:STATE_SAVING_METHOD_CLIENTorSTATE_SAVING_METHOD_SERVER.If this parameter is not specified, the default value is the value of the constant
STATE_SAVING_METHOD_CLIENT.- See Also:
-
PARTIAL_STATE_SAVING_PARAM_NAME
The
ServletContextinit parameter consulted by the runtime to determine if the partial state saving mechanism should be used.If undefined, the runtime must determine the version level of the application.
-
For applications versioned at 1.2 and under, the runtime must not use the partial state saving mechanism.
-
For applications versioned at 2.0 and above, the runtime must use the partial state saving mechanism.
If this parameter is defined, and the application is versioned at 1.2 and under, the runtime must not use the partial state saving mechanism. Otherwise, If this param is defined, and calling
toLowerCase().equals("true")on aStringrepresentation of its value returnstrue, the runtime must use partial state mechanism. Otherwise the partial state saving mechanism must not be used.- Since:
- 2.0
- See Also:
-
-
FULL_STATE_SAVING_VIEW_IDS_PARAM_NAME
The runtime must interpret the value of this parameter as a comma separated list of view IDs, each of which must have their state saved using the state saving mechanism specified in Jakarta Server Faces 1.2.
- See Also:
-
IS_SAVING_STATE
Marker within the
FacesContextattributes map to indicate we are saving state. The implementation must set this marker into the map before starting the state saving traversal and the marker must be cleared, in a finally block, after the traversal is complete.- See Also:
-
IS_BUILDING_INITIAL_STATE
Marker within the
FacesContextattributes map to indicate we are marking initial state, so themarkInitialState()method of iterating components such asUIDatacould recognize this fact and save the initial state of descendents.- Since:
- 2.1
- See Also:
-
SERIALIZE_SERVER_STATE_PARAM_NAME
If this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true, and the jakarta.faces.STATE_SAVING_METHOD is set to "server" (as indicated below), the server state must be guaranteed to be Serializable such that the aggregate state implements java.io.Serializable. The intent of this parameter is to ensure that the act of writing out the state to an ObjectOutputStream would not throw a NotSerializableException, but the runtime is not required verify this before saving the state.
- Since:
- 2.2
- See Also:
-
STATE_SAVING_METHOD_CLIENT
Constant value for the initialization parameter named by the
STATE_SAVING_METHOD_PARAM_NAMEthat indicates state saving should take place on the client.- See Also:
-
STATE_SAVING_METHOD_SERVER
Constant value for the initialization parameter named by the
STATE_SAVING_METHOD_PARAM_NAMEthat indicates state saving should take place on the server.- See Also:
-
-
Constructor Details
-
StateManager
public StateManager()
-
-
Method Details
-
saveSerializedView
Deprecated.this has been replaced bysaveView(jakarta.faces.context.FacesContext). The default implementation callssaveViewand inspects the return. If the return is anObject [], it casts the result to anObject []wrapping the first and second elements in an instance ofStateManager.SerializedView, which it then returns. Otherwise, it returnsnullReturn the tree structure and component state information for the view contained in the specified
FacesContextinstance as an object of typeStateManager.SerializedView. If there is no state information to be saved, returnnullinstead.Components may opt out of being included in the serialized view by setting their
transientproperty totrue. 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 nearestNamingContainermust have unique identifiers.- Parameters:
context-FacesContextfor the current request- Returns:
- the serialized view, or null.
- Throws:
IllegalStateException- if more than one component or facet within the sameNamingContainerin this view has the same non-nullcomponent id
-
saveView
Deprecated.The functionality of this method is now handled by
StateManagementStrategy.saveView(jakarta.faces.context.FacesContext). Return an opaqueObjectcontaining sufficient information for this same instance to restore the state of the currentUIViewRooton a subsequent request. The returned object must implementjava.io.Serializable. If there is no state information to be saved, returnnullinstead.Components may opt out of being included in the serialized view by setting their
transientproperty totrue. 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 nearestNamingContainermust have unique identifiers.For backwards compatability with existing
StateManagerimplementations, the default implementation of this method callssaveSerializedView(jakarta.faces.context.FacesContext)and creates and returns a two elementObjectarray with element zero containing thestructureproperty and element one containing thestateproperty of theSerializedView.- Parameters:
context-FacesContextfor the current request- Returns:
- the saved view.
- Throws:
IllegalStateException- if more than one component or facet within the sameNamingContainerin this view has the same non-nullcomponent id- Since:
- 1.2
-
getTreeStructureToSave
Deprecated.the distinction between tree structure and component state is now an implementation detail. The default implementation returnsnull.Convenience method, which must be called by
saveSerializedView(), to construct and return aSerializableobject 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
transientproperty totrue. 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.- Parameters:
context-FacesContextfor the current request- Returns:
- the tree structure, or null.
-
getComponentStateToSave
Deprecated.the distinction between tree structure and component state is now an implementation detail. The default implementation returnsnull.Convenience method, which must be called by
saveSerializedView(), to construct and return aSerializableobject 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
transientproperty totrue. 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.- Parameters:
context-FacesContextfor the current request- Returns:
- the component state, or null.
-
writeState
Save the state represented in the specified state
Objectinstance, in an implementation dependent manner.This method will typically simply delegate the actual writing to the
writeState()method of theResponseStateManagerinstance provided by theRenderKitbeing used to render this view. This method assumes that the caller has positioned theResponseWriterat the correct position for the saved state to be written.For backwards compatability with existing
StateManagerimplementations, the default implementation of this method checks if the argument is an instance ofObject []of length greater than or equal to two. If so, it creates aSerializedViewinstance with the tree structure coming from element zero and the component state coming from element one and calls through towriteState(jakarta.faces.context.FacesContext,jakarta.faces.application.StateManager.SerializedView). If not, does nothing.- Parameters:
context-FacesContextfor the current requeststate- the Serializable state to be written, as returned bysaveSerializedView(jakarta.faces.context.FacesContext)- Throws:
IOException- when an I/O error occurs.- Since:
- 1.2
-
writeState
@Deprecated public void writeState(FacesContext context, StateManager.SerializedView state) throws IOException Deprecated.This method has been replaced bywriteState(jakarta.faces.context.FacesContext,java.lang.Object). The default implementation calls the non-deprecated variant of the method passing anObject []as the second argument, where the first element of the array is the return fromgetStructure()and the second is the return fromgetState()on the argumentstate.Save the state represented in the specified
SerializedViewisntance, in an implementation dependent manner.This method must consult the context initialization parameter named by the symbolic constant
StateManager.STATE_SAVING_METHOD_PARAM_NAMEto 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 theResponseStateManagerinstance provided by theRenderKitbeing used to render this view. This method assumes that the caller has positioned theResponseWriterat the correct position for the saved state to be written.- Parameters:
context-FacesContextfor the current requeststate- the serialized state to be written- Throws:
IOException- when an I/O error occurs.
-
restoreView
@Deprecated public abstract UIViewRoot restoreView(FacesContext context, String viewId, String renderKitId) Deprecated.The functionality of this method is now handled by
StateManagementStrategy.restoreView(jakarta.faces.context.FacesContext, java.lang.String, java.lang.String). Restore the tree structure and the component state of the view for the specifiedviewId, in an implementation dependent manner, and return the restoredUIViewRoot. If there is no saved state information available for thisviewId, returnnullinstead.This method must consult the context initialization parameter named by the symbolic constant
StateManager.STATE_SAVING_METHOD_PARAM_NAMEto 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 theResponseStateManagerinstance provided by theRenderKitresponsible for this view.- Parameters:
context-FacesContextfor the current requestviewId- View identifier of the view to be restoredrenderKitId- the renderKitId used to render this response. Must not benull.- Returns:
- the view root, or
null. - Throws:
IllegalArgumentException- ifrenderKitIdisnull.
-
restoreTreeStructure
@Deprecated protected UIViewRoot restoreTreeStructure(FacesContext context, String viewId, String renderKitId) Deprecated.the distinction between tree structure and component state is now an implementation detail. The default implementation returnsnull.Convenience method, which must be called by
restoreView(), to construct and return aUIViewRootinstance (populated with children and facets) representing the tree structure of the component tree being restored. If no saved state information is available, returnnullinstead.- Parameters:
context-FacesContextfor the current requestviewId- View identifier of the view to be restoredrenderKitId- the renderKitId used to render this response. Must not benull.- Returns:
- the view root, or
null. - Throws:
IllegalArgumentException- ifrenderKitIdisnull.
-
restoreComponentState
@Deprecated protected void restoreComponentState(FacesContext context, UIViewRoot viewRoot, String renderKitId) Deprecated.the distinction between tree structure and component state is now an implementation detail. The default implementation does nothing.Convenience method, which must be called by
restoreView(), to restore the attributes, properties, and attached objects of all components in the restored component tree.- Parameters:
context-FacesContextfor the current requestviewRoot-UIViewRootreturned by a previous call torestoreTreeStructure()renderKitId- the renderKitId used to render this response. Must not benull.- Throws:
IllegalArgumentException- ifrenderKitIdisnull.
-
isSavingStateInClient
Method to determine if the state is saved on the client.
- Parameters:
context- the Faces context.- Returns:
trueif and only if the value of theServletContextinit parameter named by the value of the constantSTATE_SAVING_METHOD_PARAM_NAMEis equal (ignoring case) to the value of the constantSTATE_SAVING_METHOD_CLIENT.falseotherwise.- Throws:
NullPointerException- ifcontextisnull.
-
getViewState
Convenience method to return the view state as a
Stringwith noRenderKitspecific markup. This default implementation of this method will callsaveView(jakarta.faces.context.FacesContext)and passing the result to and returning the resulting value fromResponseStateManager.getViewState(jakarta.faces.context.FacesContext, Object).- Parameters:
context-FacesContextfor the current request- Returns:
- the view state.
- Since:
- 2.0
-
Serializablein the 1.0 version of the spec.