Top Description Inners Fields Constructors Methods
com.sun.faces.renderkit

public Class ClientSideStateHelper

extends StateHelper
Class Inheritance
Static Imports
com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.AutoCompleteOffOnViewState, .WebConfiguration.BooleanWebContextInitParameter.EnableViewStateIdRendering, .WebConfiguration.WebContextInitParameter.ClientStateTimeout, .WebConfiguration.WebContextInitParameter.ClientStateWriteBufferSize, com.sun.faces.renderkit.RenderKitUtils.PredefinedPostbackParameter.VIEW_STATE_PARAM, java.util.logging.Level.WARNING

This StateHelper provides the functionality associated with client-side state saving.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
ClientSideStateHelper.StringBuilderWriter

A simple Writer implementation to encapsulate a StringBuilder instance.

Field Summary

Modifier and TypeField and Description
private int
csBuffSize

Client state is generally large, so this allows some tuning to control the buffer that's used to write the client state.

private boolean
private ByteArrayGuard
guard

Enabled encryption of view state.

private static final Logger
public static final String
private long
stateTimeout

If stateTimeoutEnabled is true this value will represent the time in seconds that a particular client view state is valid for.

private boolean
stateTimeoutEnabled

Flag indicating whether or not client view state will be manipulated for and checked against a configured timeout value.

Inherited from com.sun.faces.renderkit.StateHelper:
compressViewStatefieldEndfieldMiddleserialProviderstateFieldStartwebConfig

Constructor Summary

AccessConstructor and Description
public
ClientSideStateHelper()

Construct a new ClientSideStateHelper instance.

Method Summary

Modifier and TypeMethod and Description
protected Object

Returns:

the view state reconstructed from stateString
doGetState
(FacesContext ctx, String
the Base64 encoded view state
stateString
)

Rebuilds the view state from the Base64 included String included with the request.

protected void
doWriteState(FacesContext
the Faces context.
facesContext
,
Object
view state
state
,
Writer
the Writer to write the content to
writer
)

Serializes and Base64 encodes the provided state to the provided writer/

public Object
getState(FacesContext ctx, String viewId)

Implements abstract com.sun.faces.renderkit.StateHelper.getState.

Inspects the incoming request parameters for the standardized state parameter name.

protected boolean

Returns:

false if the client state hasn't timed out, otherwise return true
hasStateExpired
(long
the time in milliseconds that the state was written to the client
stateTime
)

If the com.sun.faces.config.WebConfiguration.WebContextInitParameter#ClientStateTimeout init parameter is set, calculate the elapsed time between the time the client state was written and the time this method was invoked during restore.

protected void
init()

Initialze the various configuration options for client-side sate saving.

public boolean

Returns:

true if stateless, false otherwise.
isStateless
(FacesContext
the Faces context.
facesContext
,
String
the view id.
viewId
)

Implements abstract com.sun.faces.renderkit.StateHelper.isStateless.

Is stateless.

public void
writeState(FacesContext ctx, Object state, StringBuilder stateCapture)

Implements abstract com.sun.faces.renderkit.StateHelper.writeState.

Writes the view state as a String generated by Base64 encoding the Java Serialziation representation of the provided state

If stateCapture is null, the Base64 encoded state will be written to the client as a hidden field using the ResponseWriter from the provided FacesContext.

Inherited from com.sun.faces.renderkit.StateHelper:
createAndStoreCryptographicallyStrongTokenInSessiongetCryptographicallyStrongTokenFromSessiongetStateParamValuewriteClientWindowFieldwriteRenderKitIdField

Field Detail

csBuffSizeback to summary
private int csBuffSize

Client state is generally large, so this allows some tuning to control the buffer that's used to write the client state.

The value specified must be divisable by two as the buffer is split between character and bytes (due to how client state is written). By default, the buffer size is 8192 (per request).

See Also
com.sun.faces.config.WebConfiguration.WebContextInitParameter#ClientStateWriteBufferSize
debugSerializedStateback to summary
private boolean debugSerializedState
guardback to summary
private ByteArrayGuard guard

Enabled encryption of view state. Encryption is disabled by default.

LOGGERback to summary
private static final Logger LOGGER

Hides com.sun.faces.renderkit.StateHelper.LOGGER.

STATELESSback to summary
public static final String STATELESS
stateTimeoutback to summary
private long stateTimeout

If stateTimeoutEnabled is true this value will represent the time in seconds that a particular client view state is valid for.

See Also
com.sun.faces.config.WebConfiguration.WebContextInitParameter#ClientStateTimeout
stateTimeoutEnabledback to summary
private boolean stateTimeoutEnabled

Flag indicating whether or not client view state will be manipulated for and checked against a configured timeout value.

This flag is configured via the WebContextInitParameter.ClientStateTimeout configuration option of WebConfiguration and is disabled by default.

See Also
com.sun.faces.config.WebConfiguration.WebContextInitParameter#ClientStateTimeout

Constructor Detail

ClientSideStateHelperback to summary
public ClientSideStateHelper()

Construct a new ClientSideStateHelper instance.

Method Detail

doGetStateback to summary
protected Object doGetState(FacesContext ctx, String stateString)

Rebuilds the view state from the Base64 included String included with the request.

Parameters
stateString:String

the Base64 encoded view state

Returns:Object

the view state reconstructed from stateString

doWriteStateback to summary
protected void doWriteState(FacesContext facesContext, Object state, Writer writer) throws IOException

Serializes and Base64 encodes the provided state to the provided writer/

Parameters
facesContext:FacesContext

the Faces context.

state:Object

view state

writer:Writer

the Writer to write the content to

Exceptions
IOException:
if an error occurs writing the state to the client
getStateback to summary
public Object getState(FacesContext ctx, String viewId) throws IOException

Implements abstract com.sun.faces.renderkit.StateHelper.getState.

Inspects the incoming request parameters for the standardized state parameter name. In this case, the parameter value will be a Base64 encoded string previously encoded by ServerSideStateHelper#writeState(FacesContext, Object, StringBuilder).

The string will be Base64-decoded and the state reconstructed using standard Java serialization.

Annotations
@Override
See Also
StateHelper#getState(jakarta.faces.context.FacesContext, java.lang.String)
hasStateExpiredback to summary
protected boolean hasStateExpired(long stateTime)

If the com.sun.faces.config.WebConfiguration.WebContextInitParameter#ClientStateTimeout init parameter is set, calculate the elapsed time between the time the client state was written and the time this method was invoked during restore. If the client state has expired, return true. If the client state hasn't expired, or the init parameter wasn't set, return false.

Parameters
stateTime:long

the time in milliseconds that the state was written to the client

Returns:boolean

false if the client state hasn't timed out, otherwise return true

initback to summary
protected void init()

Initialze the various configuration options for client-side sate saving.

isStatelessback to summary
public boolean isStateless(FacesContext facesContext, String viewId) throws IllegalStateException

Implements abstract com.sun.faces.renderkit.StateHelper.isStateless.

Is stateless.

Parameters
facesContext:FacesContext

the Faces context.

viewId:String

the view id.

Returns:boolean

true if stateless, false otherwise.

Annotations
@Override
Exceptions
IllegalStateException:
when the request was not a postback.
writeStateback to summary
public void writeState(FacesContext ctx, Object state, StringBuilder stateCapture) throws IOException

Implements abstract com.sun.faces.renderkit.StateHelper.writeState.

Writes the view state as a String generated by Base64 encoding the Java Serialziation representation of the provided state

If stateCapture is null, the Base64 encoded state will be written to the client as a hidden field using the ResponseWriter from the provided FacesContext.

If stateCapture is not null, the Base64 encoded state will be appended to the provided StringBuilder without any markup included or any content written to the client.

Annotations
@Override
See Also
StateHelper#writeState(jakarta.faces.context.FacesContext, java.lang.Object, java.lang.StringBuilder)
com.sun.faces.renderkit back to summary

protected final Class ClientSideStateHelper.StringBuilderWriter

extends Writer
Class Inheritance

A simple Writer implementation to encapsulate a StringBuilder instance.

Field Summary

Modifier and TypeField and Description
private final StringBuilder
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public Writer
append(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
csq
)

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Appends the specified character sequence to this writer.

public Writer
append(CharSequence
The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
csq
,
int
The index of the first character in the subsequence
start
,
int
The index of the character following the last character in the subsequence
end
)

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Appends a subsequence of the specified character sequence to this writer.

public Writer
append(char
The 16-bit character to append
c
)

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Appends the specified character to this writer.

public void
close()

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Closes the stream, flushing it first.

public void
flush()

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Flushes the stream.

public void
write(int
int specifying a character to be written
c
)

Overrides java.io.Writer.write.

Writes a single character.

public void
write(char[]
Array of characters to be written
cbuf
)

Overrides java.io.Writer.write.

Writes an array of characters.

public void
write(String
String to be written
str
)

Overrides java.io.Writer.write.

Writes a string.

public void
write(String
A String
str
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Overrides java.io.Writer.write.

Writes a portion of a string.

public void
write(char[]
Array of characters
cbuf
,
int
Offset from which to start writing characters
off
,
int
Number of characters to write
len
)

Implements abstract java.io.Writer.write.

Writes a portion of an array of characters.

Inherited from java.io.Writer:
nullWriter

Field Detail

sbback to summary
private final StringBuilder sb

Constructor Detail

StringBuilderWriterback to summary
protected StringBuilderWriter(StringBuilder sb)

Method Detail

appendback to summary
public Writer append(CharSequence csq) throws IOException

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Doc from java.io.Writer.append.

Appends the specified character sequence to this writer.

An invocation of this method of the form out.append(csq) when csq is not null, behaves in exactly the same way as the invocation

out.write(csq.toString())
out.write(csq.toString())

Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking the toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

Parameters
csq:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.

Returns:Writer

This writer

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
appendback to summary
public Writer append(CharSequence csq, int start, int end) throws IOException

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Doc from java.io.Writer.append.

Appends a subsequence of the specified character sequence to this writer.

An invocation of this method of the form out.append(csq, start, end) when csq is not null behaves in exactly the same way as the invocation

out.write(csq.subSequence(start, end).toString())
out.write(csq.subSequence(start, end).toString())
Parameters
csq:CharSequence

The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".

start:int

The index of the first character in the subsequence

end:int

The index of the character following the last character in the subsequence

Returns:Writer

This writer

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
appendback to summary
public Writer append(char c) throws IOException

Overrides java.io.Writer.append.

Implements java.lang.Appendable.append.

Doc from java.io.Writer.append.

Appends the specified character to this writer.

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

out.write(c)
out.write(c)
Parameters
c:char

The 16-bit character to append

Returns:Writer

This writer

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
closeback to summary
public void close() throws IOException

Implements abstract java.io.Writer.close.

Implements java.io.Closeable.close.

Doc from java.io.Writer.close.

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

Implements abstract java.io.Writer.flush.

Implements java.io.Flushable.flush.

Doc from java.io.Writer.flush.

Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(int c) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.

Subclasses that intend to support efficient single-character output should override this method.

Parameters
c:int

int specifying a character to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes an array of characters.

Parameters
cbuf:char[]

Array of characters to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a string.

Parameters
str:String

String to be written

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str, int off, int len) throws IOException

Overrides java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of a string.

Parameters
str:String

A String

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Implements abstract java.io.Writer.write.

Doc from java.io.Writer.write.

Writes a portion of an array of characters.

Parameters
cbuf:char[]

Array of characters

off:int

Offset from which to start writing characters

len:int

Number of characters to write

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs