public class ResponseStateManagerImpl extends ResponseStateManager
A ResonseStateManager
implementation
for the default HTML render kit.
CLIENT_WINDOW_PARAM, CLIENT_WINDOW_URL_PARAM, NON_POSTBACK_VIEW_TOKEN_PARAM, RENDER_KIT_ID_PARAM, VIEW_STATE_PARAM
Constructor and Description |
---|
ResponseStateManagerImpl() |
Modifier and Type | Method and Description |
---|---|
String |
getCryptographicallyStrongTokenFromSession(FacesContext context)
Compliant implementations must return a cryptographically strong token for use to protect views in this application. |
Object |
getState(FacesContext context,
String viewId)
The implementation must
inspect the current request and return
an Object representing the tree structure and component state
passed in to a previous invocation of
ResponseStateManager.writeState(javax.faces.context.FacesContext,java.lang.Object) . |
Object |
getTreeStructureToRestore(FacesContext context,
String viewId)
The implementation must inspect the current request and return
the tree structure Object passed to it on a previous invocation of
writeState() . |
String |
getViewState(FacesContext context,
Object state)
Return the specified state as a
String without any markup
related to the rendering technology supported by this ResponseStateManager. |
boolean |
isPostback(FacesContext context)
Return true if the current request is a postback.
|
boolean |
isStateless(FacesContext facesContext,
String viewId)
If the preceding call to |
void |
writeState(FacesContext context,
Object state)
Take the argument
state and write it into the
output using the current ResponseWriter , which must be
correctly positioned already. |
getComponentStateToRestore, writeState
public boolean isPostback(FacesContext context)
ResponseStateManager
Return true if the current request is a postback. This method
is leveraged from the Restore View Phase to determine if
ViewHandler.restoreView(javax.faces.context.FacesContext, java.lang.String)
or ViewHandler.createView(javax.faces.context.FacesContext, java.lang.String)
should be called.
The default implementation must return true
if this
ResponseStateManager
instance wrote out state on a
previous request to which this request is a postback,
false
otherwise.
The implementation of this method for the Standard HTML
RenderKit must consult the ExternalContext
's
requestParameterMap
and return true
if
and only if there is a key equal to the value of the symbolic
constant ResponseStateManager.VIEW_STATE_PARAM
.
For backwards compatibility with implementations of
ResponseStateManager
prior to Jakarta Server Faces 1.2, a default
implementation is provided that consults the ExternalContext
's requestParameterMap
and return
true
if its size is greater than 0.
isPostback
in class ResponseStateManager
context
- the FacesContext
for the current request.ResponseStateManager.isPostback(javax.faces.context.FacesContext)
public String getCryptographicallyStrongTokenFromSession(FacesContext context)
ResponseStateManager
Compliant implementations must return a
cryptographically strong token for use to protect views in this
application. For backwards compatability with earlier revisions, a
default implementation is provided that simply returns null
.
getCryptographicallyStrongTokenFromSession
in class ResponseStateManager
context
- the FacesContext
for the current requestpublic Object getState(FacesContext context, String viewId)
ResponseStateManager
The implementation must
inspect the current request and return
an Object representing the tree structure and component state
passed in to a previous invocation of ResponseStateManager.writeState(javax.faces.context.FacesContext,java.lang.Object)
.
If the state saving method for this
application is StateManager.STATE_SAVING_METHOD_CLIENT
,
writeState()
will have encrypted the state in a tamper
evident manner. If the state fails to decrypt, or decrypts but
indicates evidence of tampering, a
ProtectedViewException
must be thrown.
For backwards compatability with existing
ResponseStateManager
implementations, the default
implementation of this method calls ResponseStateManager.getTreeStructureToRestore(javax.faces.context.FacesContext, java.lang.String)
and ResponseStateManager.getComponentStateToRestore(javax.faces.context.FacesContext)
and creates and returns a two
element Object
array with element zero containing
the structure
property and element one containing
the state
property of the
SerializedView
.
getState
in class ResponseStateManager
context
- The FacesContext
instance for the current requestviewId
- View identifier of the view to be restoredwriteState
. If this is an initial request, this
method returns null
.ResponseStateManager.getState(javax.faces.context.FacesContext, java.lang.String)
public void writeState(FacesContext context, Object state) throws IOException
ResponseStateManager
Take the argument
state
and write it into the
output using the current ResponseWriter
, which must be
correctly positioned already.
Call FacesContext.getViewRoot()
.
If StateHolder.isTransient()
returns true
, take implementation specific action so that the
following call to ResponseStateManager.isStateless(javax.faces.context.FacesContext, java.lang.String)
returns true
and return.
Otherwise, proceed as follows.
If the state is to be written out to hidden fields, the implementation must take care to make all necessary character replacements to make the Strings suitable for inclusion as an HTTP request paramater.
If the state saving method for this application is StateManager.STATE_SAVING_METHOD_CLIENT
,
the implementation must
encrypt the state to be saved to the
client in a tamper evident
manner.
If the state saving method for this application is StateManager.STATE_SAVING_METHOD_SERVER
,
and the current request is an Ajax
request
PartialViewContext.isAjaxRequest()
returns
true
), use the current view state identifier if it is
available (do not generate a new identifier).
Write out the render kit identifier associated with this
ResponseStateManager
implementation with the name
as the value of the String
constant
ResponseStateManager.RENDER_KIT_ID_PARAM
. The
render kit identifier must not be written if:
Application.getDefaultRenderKitId()
orjavax.faces.render.RenderKitFactory.HTML_BASIC_RENDER_KIT
and
Application.getDefaultRenderKitId()
returns null
.
For backwards compatability with existing
ResponseStateManager
implementations, the default
implementation of this method checks if the argument is an
instance of SerializedView
. If so, it calls through
to ResponseStateManager.writeState(javax.faces.context.FacesContext,javax.faces.application.StateManager.SerializedView)
.
If not, it expects the state to be a two element Object array. It creates
an instance of SerializedView
and
stores the state as the treeStructure, and passes it to ResponseStateManager.writeState(javax.faces.context.FacesContext,javax.faces.application.StateManager.SerializedView)
.
The ClientWindow
must be written using these
steps. Call ExternalContext.getClientWindow()
. If the
result is null
, take no further action regarding the
ClientWindow
. If the result is
non-null
, write a hidden field whose name is ResponseStateManager.CLIENT_WINDOW_PARAM
and whose id is
<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>javax.faces.ClientWindow<SEP><UNIQUE_PER_VIEW_NUMBER>
where <SEP> is the currently configured
UINamingContainer.getSeparatorChar()
.
<VIEW_ROOT_CONTAINER_CLIENT_ID> is the return from
UIViewRoot.getContainerClientId()
on the view from
whence this state originated. <UNIQUE_PER_VIEW_NUMBER> is
a number that must be unique within this view, but must not be
included in the view state. The value of the field is implementation
dependent but must uniquely identify this window within the user's session.
writeState
in class ResponseStateManager
context
- The FacesContext
instance for the current requeststate
- The serialized state information previously savedIOException
- if the state argument is not an array of length 2.ResponseStateManager.writeState(javax.faces.context.FacesContext, java.lang.Object)
public String getViewState(FacesContext context, Object state)
ResponseStateManager
Return the specified state as a String
without any markup
related to the rendering technology supported by this ResponseStateManager.
getViewState
in class ResponseStateManager
context
- the FacesContext
for the current requeststate
- the state from which the String version will be generated
fromResponseStateManager.getViewState(javax.faces.context.FacesContext, java.lang.Object)
public Object getTreeStructureToRestore(FacesContext context, String viewId)
ResponseStateManager
The implementation must inspect the current request and return
the tree structure Object passed to it on a previous invocation of
writeState()
.
getTreeStructureToRestore
in class ResponseStateManager
context
- The FacesContext
instance for the current requestviewId
- View identifier of the view to be restoredpublic boolean isStateless(FacesContext facesContext, String viewId)
ResponseStateManager
If the preceding call to ResponseStateManager.writeState(javax.faces.context.FacesContext, java.lang.Object)
was stateless, return true
. If the preceding call to writeState()
was
stateful, return false
. Otherwise throw IllegalStateException
.
To preserve backward compatibility
with custom implementations that may have extended from an earlier
version of this class, an implementation is provided that returns
false
. A compliant implementation must override this
method to take the specified action.
isStateless
in class ResponseStateManager
facesContext
- the Faces context.viewId
- the view id.IllegalStateException
- when the request is not a postback.Comments to: faces-dev@eclipse.org.
Copyright © 2019 Eclipse Foundation. All rights reserved.
Use is subject to license terms.