Class StateManager
- java.lang.Object
-
- jakarta.faces.application.StateManager
-
- Direct Known Subclasses:
StateManagerWrapper
public abstract class StateManager extends Object
StateManager directs the process of saving and restoring the view between requests. An implementation of this class must be thread-safe. The
StateManagerinstance for an application is retrieved from theApplicationinstance, and thus cannot know any details of the markup language created by theRenderKitbeing used to render a view. TheStateManagerutilizes a helper object (ResponseStateManager), that is provided by theRenderKitimplementation and is therefore aware of the markup language details.
-
-
Field Summary
Fields Modifier and Type Field Description static StringFULL_STATE_SAVING_VIEW_IDS_PARAM_NAMEThe 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 Faces 1.2.static StringIS_BUILDING_INITIAL_STATEMarker 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 StringIS_SAVING_STATEMarker within theFacesContextattributes map to indicate we are saving state.static StringPARTIAL_STATE_SAVING_PARAM_NAMETheServletContextinit parameter consulted by the runtime to determine if the partial state saving mechanism should be used.static StringSERIALIZE_SERVER_STATE_PARAM_NAMEIf 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 StringSTATE_SAVING_METHOD_CLIENTConstant value for the initialization parameter named by theSTATE_SAVING_METHOD_PARAM_NAMEthat indicates state saving should take place on the client.static StringSTATE_SAVING_METHOD_PARAM_NAMETheServletContextinit parameter consulted by theStateManagerto tell where the state should be saved.static StringSTATE_SAVING_METHOD_SERVERConstant value for the initialization parameter named by theSTATE_SAVING_METHOD_PARAM_NAMEthat indicates state saving should take place on the server.
-
Constructor Summary
Constructors Constructor Description StateManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetViewState(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.voidwriteState(FacesContext context, Object state)Save the state represented in the specified stateObjectinstance, in an implementation dependent manner.
-
-
-
Field Detail
-
STATE_SAVING_METHOD_PARAM_NAME
public static final String 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:
- Constant Field Values
-
PARTIAL_STATE_SAVING_PARAM_NAME
public static final String 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:
- Constant Field Values
-
-
FULL_STATE_SAVING_VIEW_IDS_PARAM_NAME
public static final String 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 Faces 1.2.
- See Also:
- Constant Field Values
-
IS_SAVING_STATE
public static final String 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:
- Constant Field Values
-
IS_BUILDING_INITIAL_STATE
public static final String 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:
- Constant Field Values
-
SERIALIZE_SERVER_STATE_PARAM_NAME
public static final String 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:
- Constant Field Values
-
STATE_SAVING_METHOD_CLIENT
public static final String 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:
- Constant Field Values
-
STATE_SAVING_METHOD_SERVER
public static final String 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:
- Constant Field Values
-
-
Method Detail
-
writeState
public void writeState(FacesContext context, Object state) throws IOException
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.- Parameters:
context-FacesContextfor the current requeststate- the state to be written- Throws:
IOException- when an I/O error occurs.- Since:
- 1.2
-
isSavingStateInClient
public boolean isSavingStateInClient(FacesContext context)
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
public String getViewState(FacesContext context)
Convenience method to return the view state as a
Stringwith noRenderKitspecific markup. This default implementation of this method will callStateManagementStrategy.saveView(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
-
-