public abstract class StateManagementStrategy
extends java.lang.Object
Encapsulate the saving and restoring of the view to enable the VDL to take
over the responsibility for handling this feature. Because ViewDeclarationLanguage.getStateManagementStrategy(jakarta.faces.context.FacesContext, java.lang.String)
is required to return null
for Jakarta Server Pages views and non-null
for views authored
in Facelets for Jakarta Server Faces 2, this specification only applies to Facelets for Jakarta Server Faces 2.
Implementations must call UIComponent.visitTree(jakarta.faces.component.visit.VisitContext, jakarta.faces.component.visit.VisitCallback)
on the
UIViewRoot
to perform the saving and restoring of the view in the saveView(jakarta.faces.context.FacesContext)
and restoreView(jakarta.faces.context.FacesContext, java.lang.String, java.lang.String)
methods, respectively.
Constructor and Description |
---|
StateManagementStrategy() |
Modifier and Type | Method and Description |
---|---|
abstract UIViewRoot |
restoreView(FacesContext context,
java.lang.String viewId,
java.lang.String renderKitId)
Restore the state of the view with information in the request. |
abstract java.lang.Object |
saveView(FacesContext context)
Return the state of the current view in an |
public abstract java.lang.Object saveView(FacesContext context)
Return the state of the current view in an Object
that
implements Serializable
and can be passed to
java.io.ObjectOutputStream.writeObject()
without causing a java.io.NotSerializableException
to be thrown. The default implementation must perform the following algorithm or its semantic equivalent,
explicitly performing all the steps listed here.
If the UIViewRoot
of the current view is marked transient
, return null
immediately.
Traverse the view and verify that each of the client ids are unique. Throw IllegalStateException
if more
than one client id are the same.
Visit the tree using UIComponent.visitTree(jakarta.faces.component.visit.VisitContext, jakarta.faces.component.visit.VisitCallback)
. For each node, call
StateHolder.saveState(jakarta.faces.context.FacesContext)
, saving the returned Object
in a way such that it
can be restored given only its client id. Special care must be taken to handle the case of components that were added
or deleted programmatically during this lifecycle traversal, rather than by the VDL.
The implementation must ensure that the StateHolder.saveState(jakarta.faces.context.FacesContext)
method is called for
each node in the tree.
The data structure used to save the state obtained by executing the above algorithm must be
Serializable
, and all of the elements within the data structure must also be Serializable
.
context
- the FacesContext
for this request.public abstract UIViewRoot restoreView(FacesContext context, java.lang.String viewId, java.lang.String renderKitId)
Restore the state of the view with information in the request. The default implementation must perform the following algorithm or its semantic equivalent.
As in the case of restore view on an initial request, the view metadata must be restored and properly handled as
well. Obtain the ViewMetadata
for the current viewId
, and from that call
ViewMetadata.createMetadataView(jakarta.faces.context.FacesContext)
. Store the resultant UIViewRoot
in the FacesContext
. Obtain
the state of the UIViewRoot
from the state Object
returned from
ResponseStateManager.getState(jakarta.faces.context.FacesContext, java.lang.String)
and pass that to UIViewRoot.restoreViewScopeState(jakarta.faces.context.FacesContext, java.lang.Object)
.
Build the view from the markup. For all components in the view that do not have an explicitly assigned id in the markup, the values of those ids must be the same as on an initial request for this view. This view will not contain any components programmatically added during the previous lifecycle run, and it will contain components that were programmatically deleted on the previous lifecycle run. Both of these cases must be handled.
Call ResponseStateManager.getState(jakarta.faces.context.FacesContext, java.lang.String)
to obtain the data structure returned from the
previous call to saveView(jakarta.faces.context.FacesContext)
.
Visit the tree using UIComponent.visitTree(jakarta.faces.component.visit.VisitContext, jakarta.faces.component.visit.VisitCallback)
. For each node, call
StateHolder.restoreState(jakarta.faces.context.FacesContext, java.lang.Object)
, passing the state saved corresponding to the current client
id.
Ensure that any programmatically deleted components are removed.
Ensure any programmatically added components are added.
The implementation must ensure that the StateHolder.restoreState(jakarta.faces.context.FacesContext, java.lang.Object)
method is called for
each node in the tree, except for those that were programmatically deleted on the previous run through the lifecycle.
context
- the FacesContext
for this requestviewId
- the view identifier for which the state should be restoredrenderKitId
- the render kit id for this state.