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

public Class ViewHandlerImpl

extends ViewHandler
Class Inheritance
Annotations
@Deprecated
Static Imports
com.sun.faces.renderkit.RenderKitUtils.PredefinedPostbackParameter.RENDER_KIT_ID_PARAM

Deprecated

Refer to com.sun.faces.application.view.MultiViewHandler

This is the default implementation for JSF 1.2.

While this class isn't used by the 2.0 runtime, it's kept for binary compatibility with those that extend from this class directly.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ViewHandlerImpl.WriteBehindStateWriter

Thanks to the Facelets folks for some of the concepts incorporated into this class.

Field Summary

Modifier and TypeField and Description
private ApplicationAssociate
private int
private String[]
private static final Logger
Inherited from javax.faces.application.ViewHandler:
CHARACTER_ENCODING_KEYDEFAULT_FACELETS_SUFFIXDEFAULT_SUFFIXDEFAULT_SUFFIX_PARAM_NAMEDISABLE_FACELET_JSF_VIEWHANDLER_PARAM_NAMEFACELETS_BUFFER_SIZE_PARAM_NAMEFACELETS_DECORATORS_PARAM_NAMEFACELETS_LIBRARIES_PARAM_NAMEFACELETS_REFRESH_PERIOD_PARAM_NAMEFACELETS_SKIP_COMMENTS_PARAM_NAMEFACELETS_SUFFIX_PARAM_NAMEFACELETS_VIEW_MAPPINGS_PARAM_NAME

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Locale
calculateLocale(FacesContext
FacesContext for the current request
context
)

Implements abstract javax.faces.application.ViewHandler.calculateLocale.

Returns an appropriate Locale to use for this and subsequent requests for the current client.

public String
calculateRenderKitId(FacesContext
FacesContext for the current request
context
)

Implements abstract javax.faces.application.ViewHandler.calculateRenderKitId.

Return an appropriate renderKitId for this and subsequent requests from the current client.

private String

Returns:

the view ID with an altered suffix mapping (if necessary)
convertViewId
(FacesContext
current FacesContext
context
,
String
incoming view ID
viewId
)

Adjust the viewID per the requirements of renderView.

public UIViewRoot
createView(FacesContext
the Faces context.
context
,
String
the view id.
viewId
)

Implements abstract javax.faces.application.ViewHandler.createView.

Create and return a new UIViewRoot instance initialized with information from the argument FacesContext and viewId.

private void
doRenderView(FacesContext
the FacesContext for the current request
context
,
UIViewRoot
the view to render
viewToRender
)

This is a separate method to account for handling the content after the view tag.

private boolean

Returns:

true if the response should be immediately flushed to the client, otherwise false
executePageToBuildView
(FacesContext
the FacesContext for the current request
context
,
UIViewRoot
the view to build
viewToExecute
)

Execute the target view.

protected Locale

Returns:

the Locale based on pref and the matching alogritm specified in JSTL 8.3.2
findMatch
(FacesContext
the FacesContext for the current request
context
,
Locale
the preferred locale
pref
)

Attempts to find a matching locale based on pref and list of supported locales, using the matching algorithm as described in JSTL 8.3.2.

public String
getActionURL(FacesContext
FacesContext for this request
context
,
String
View identifier of the desired view
viewId
)

Implements abstract javax.faces.application.ViewHandler.getActionURL.

If the value returned from this method is used as the file argument to the four-argument constructor for java.net.URL (assuming appropriate values are used for the first three arguments), then a client making a request to the toExternalForm() of that URL will select the argument viewId for traversing the JSF lifecycle.

private ApplicationAssociate
public String
getResourceURL(FacesContext
FacesContext for the current request
context
,
String
Resource path to convert to a URL
path
)

Implements abstract javax.faces.application.ViewHandler.getResourceURL.

If the value returned from this method is used as the file argument to the four-argument constructor for java.net.URL (assuming appropriate values are used for the first three arguments), then a client making a request to the toExternalForm() of that URL will select the argument path for direct rendering.

public String
getWebsocketURL(FacesContext
FacesContext for the current request.
context
,
String
The channel name of the websocket.
channel
)

Implements abstract javax.faces.application.ViewHandler.getWebsocketURL.

If the value returned from this method is used as the file argument to the four-argument constructor for java.net.URL (assuming appropriate values are used for the first three arguments), then a client making a push handshake request to the toExternalForm() of that URL will select the argument channel for connecting the websocket push channel in the current view.

private static ViewHandlerResponseWrapper
public void
private String

Returns:

the URI without additional FacesServlet mappings
normalizeRequestURI
(String
the servlet request path
uri
,
String
the FacesServlet mapping used for this request
mapping
)

if the specified mapping is a prefix mapping, and the provided request URI (usually the value from ExternalContext.getRequestServletPath()) starts with mapping + '/', prune the mapping from the URI and return it, otherwise, return the original URI.

public void
renderView(FacesContext
FacesContext for the current request
context
,
UIViewRoot
the view to render
viewToRender
)

Implements abstract javax.faces.application.ViewHandler.renderView.

Perform whatever actions are required to render the response view to the response object associated with the current FacesContext.

public UIViewRoot
restoreView(FacesContext
FacesContext for the current request
context
,
String
the view identifier for the current request
viewId
)

Implements abstract javax.faces.application.ViewHandler.restoreView.

Perform whatever actions are required to restore the view associated with the specified FacesContext and viewId.

private void
public void
writeState(FacesContext
FacesContext for the current request
context
)

Implements abstract javax.faces.application.ViewHandler.writeState.

Take any appropriate action to either immediately write out the current state information (by calling StateManager#writeState, or noting where state information should later be written.

Inherited from javax.faces.application.ViewHandler:
addProtectedViewcalculateCharacterEncodingderiveLogicalViewIdderiveViewIdgetBookmarkableURLgetProtectedViewsUnmodifiablegetRedirectURLgetViewDeclarationLanguagegetViewsgetViewsremoveProtectedView

Field Detail

associateback to summary
private ApplicationAssociate associate
bufSizeback to summary
private int bufSize
configuredExtensionsback to summary
private String[] configuredExtensions
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

ViewHandlerImplback to summary
public ViewHandlerImpl()

Method Detail

calculateLocaleback to summary
public Locale calculateLocale(FacesContext context)

Implements abstract javax.faces.application.ViewHandler.calculateLocale.

Doc from javax.faces.application.ViewHandler.calculateLocale.

Returns an appropriate Locale to use for this and subsequent requests for the current client.

Parameters
context:FacesContext

FacesContext for the current request

Returns:Locale

the locale.

Annotations
@Override
calculateRenderKitIdback to summary
public String calculateRenderKitId(FacesContext context)

Implements abstract javax.faces.application.ViewHandler.calculateRenderKitId.

Doc from javax.faces.application.ViewHandler.calculateRenderKitId.

Return an appropriate renderKitId for this and subsequent requests from the current client. It is an error for this method to return null.

The default return value is javax.faces.render.RenderKitFactory#HTML_BASIC_RENDER_KIT.

Parameters
context:FacesContext

FacesContext for the current request

Returns:String

the render kit id.

Annotations
@Override
convertViewIdback to summary
private String convertViewId(FacesContext context, String viewId)

Adjust the viewID per the requirements of renderView.

Parameters
context:FacesContext

current FacesContext

viewId:String

incoming view ID

Returns:String

the view ID with an altered suffix mapping (if necessary)

createViewback to summary
public UIViewRoot createView(FacesContext context, String viewId)

Implements abstract javax.faces.application.ViewHandler.createView.

Doc from javax.faces.application.ViewHandler.createView.

Create and return a new UIViewRoot instance initialized with information from the argument FacesContext and viewId. Locate the ViewDeclarationLanguage implementation for the VDL used in the view. The argument viewId must be converted to a physical viewId that can refer to an actual resource suitable for use by the ViewDeclarationLanguage ViewDeclarationLanguage#createView, which must be called by this method.

Parameters
context:FacesContext

the Faces context.

viewId:String

the view id.

Returns:UIViewRoot

the viewroot.

Annotations
@Override
doRenderViewback to summary
private void doRenderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException

This is a separate method to account for handling the content after the view tag.

Create a new ResponseWriter around this response's Writer. Set it into the FacesContext, saving the old one aside.

call encodeBegin(), encodeChildren(), encodeEnd() on the argument UIViewRoot.

Restore the old ResponseWriter into the FacesContext.

Write out the after view content to the response's writer.

Flush the response buffer, and remove the after view content from the request scope.

Parameters
context:FacesContext

the FacesContext for the current request

viewToRender:UIViewRoot

the view to render

Exceptions
IOException:
if an error occurs rendering the view to the client
FacesException:
if some error occurs within the framework processing
executePageToBuildViewback to summary
private boolean executePageToBuildView(FacesContext context, UIViewRoot viewToExecute) throws IOException

Execute the target view. If the HTTP status code range is not 2xx, then return true to indicate the response should be immediately flushed by the caller so that conditions such as 404 are properly handled.

Parameters
context:FacesContext

the FacesContext for the current request

viewToExecute:UIViewRoot

the view to build

Returns:boolean

true if the response should be immediately flushed to the client, otherwise false

Exceptions
IOException:
if an error occurs executing the page
findMatchback to summary
protected Locale findMatch(FacesContext context, Locale pref)

Attempts to find a matching locale based on pref and list of supported locales, using the matching algorithm as described in JSTL 8.3.2.

Parameters
context:FacesContext

the FacesContext for the current request

pref:Locale

the preferred locale

Returns:Locale

the Locale based on pref and the matching alogritm specified in JSTL 8.3.2

getActionURLback to summary
public String getActionURL(FacesContext context, String viewId)

Implements abstract javax.faces.application.ViewHandler.getActionURL.

Doc from javax.faces.application.ViewHandler.getActionURL.

If the value returned from this method is used as the file argument to the four-argument constructor for java.net.URL (assuming appropriate values are used for the first three arguments), then a client making a request to the toExternalForm() of that URL will select the argument viewId for traversing the JSF lifecycle. Please see section JSF.7.6.2 for the complete specification, especially for details related to view protection using the javax.faces.render.ResponseStateManager#NON_POSTBACK_VIEW_TOKEN_PARAM and the behavior when the current request is to a URL for which the FacesServlet has an exact mapping as defined by Servlet.12.2.

Parameters
context:FacesContext

FacesContext for this request

viewId:String

View identifier of the desired view

Returns:String

the action url.

Annotations
@Override
getAssociateback to summary
private ApplicationAssociate getAssociate(FacesContext context)
getResourceURLback to summary
public String getResourceURL(FacesContext context, String path)

Implements abstract javax.faces.application.ViewHandler.getResourceURL.

Doc from javax.faces.application.ViewHandler.getResourceURL.

If the value returned from this method is used as the file argument to the four-argument constructor for java.net.URL (assuming appropriate values are used for the first three arguments), then a client making a request to the toExternalForm() of that URL will select the argument path for direct rendering. If the specified path starts with a slash, it must be treated as context relative; otherwise, it must be treated as relative to the action URL of the current view.

Parameters
context:FacesContext

FacesContext for the current request

path:String

Resource path to convert to a URL

Returns:String

the resource URL.

Annotations
@Override
getWebsocketURLback to summary
public String getWebsocketURL(FacesContext context, String channel)

Implements abstract javax.faces.application.ViewHandler.getWebsocketURL.

Doc from javax.faces.application.ViewHandler.getWebsocketURL.

If the value returned from this method is used as the file argument to the four-argument constructor for java.net.URL (assuming appropriate values are used for the first three arguments), then a client making a push handshake request to the toExternalForm() of that URL will select the argument channel for connecting the websocket push channel in the current view. It must match the PushContext#URI_PREFIX of the endpoint.

Parameters
context:FacesContext

FacesContext for the current request.

channel:String

The channel name of the websocket.

Returns:String

the websocket URL.

Annotations
@Override
getWrapperback to summary
private static ViewHandlerResponseWrapper getWrapper(ExternalContext extContext)
initViewback to summary
public void initView(FacesContext context) throws FacesException

Overrides javax.faces.application.ViewHandler.initView.

Do not call the default implementation of ViewHandler#initView(javax.faces.context.FacesContext) if the javax.faces.context.ExternalContext#getRequestCharacterEncoding() returns a non-null result.

Parameters
context:FacesContext

Doc from javax.faces.application.ViewHandler.initView.

the Faces context.

Annotations
@Override
Exceptions
FacesException:

Doc from javax.faces.application.ViewHandler.initView.

if a problem occurs setting the encoding, such as the UnsupportedEncodingException thrown by the underlying Servlet or Portlet technology when the encoding is not supported.

See Also
ViewHandler#initView(javax.faces.context.FacesContext)
normalizeRequestURIback to summary
private String normalizeRequestURI(String uri, String mapping)

if the specified mapping is a prefix mapping, and the provided request URI (usually the value from ExternalContext.getRequestServletPath()) starts with mapping + '/', prune the mapping from the URI and return it, otherwise, return the original URI.

Parameters
uri:String

the servlet request path

mapping:String

the FacesServlet mapping used for this request

Returns:String

the URI without additional FacesServlet mappings

Since
1.2
renderViewback to summary
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException

Implements abstract javax.faces.application.ViewHandler.renderView.

Doc from javax.faces.application.ViewHandler.renderView.

Perform whatever actions are required to render the response view to the response object associated with the current FacesContext.

Otherwise, the default implementation must obtain a reference to the ViewDeclarationLanguage for the viewId of the argument viewToRender and call its ViewDeclarationLanguage#renderView method, returning the result and not swallowing any exceptions thrown by that method.

Parameters
context:FacesContext

FacesContext for the current request

viewToRender:UIViewRoot

the view to render

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
FacesException:
if a servlet error occurs
restoreViewback to summary
public UIViewRoot restoreView(FacesContext context, String viewId)

Implements abstract javax.faces.application.ViewHandler.restoreView.

Doc from javax.faces.application.ViewHandler.restoreView.

Perform whatever actions are required to restore the view associated with the specified FacesContext and viewId. It may delegate to the restoreView of the associated StateManager to do the actual work of restoring the view. If there is no available state for the specified viewId, return null.

Otherwise, the default implementation must obtain a reference to the ViewDeclarationLanguage for this viewId and call its ViewDeclarationLanguage#restoreView method, returning the result and not swallowing any exceptions thrown by that method.

Parameters
context:FacesContext

FacesContext for the current request

viewId:String

the view identifier for the current request

Returns:UIViewRoot

the restored view root, or null.

Annotations
@Override
send404Errorback to summary
private void send404Error(FacesContext context)
writeStateback to summary
public void writeState(FacesContext context) throws IOException

Implements abstract javax.faces.application.ViewHandler.writeState.

Doc from javax.faces.application.ViewHandler.writeState.

Take any appropriate action to either immediately write out the current state information (by calling StateManager#writeState, or noting where state information should later be written.

This method must do nothing if the current request is an Ajax request. When responding to Ajax requests, the state is obtained by calling StateManager#getViewState and then written into the Ajax response during final encoding (javax.faces.context.PartialViewContext#processPartial(javax.faces.event.PhaseId)) .

Parameters
context:FacesContext

FacesContext for the current request

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
com.sun.faces.application back to summary

private final Class ViewHandlerImpl.WriteBehindStateWriter

extends Writer
Class Inheritance

Thanks to the Facelets folks for some of the concepts incorporated into this class.

Field Summary

Modifier and TypeField and Description
private char[]
private int
private FacesContext
private static final ThreadLocal<ViewHandlerImpl.WriteBehindStateWriter>
private FastStringWriter
private Writer
private Writer
private static final int
private boolean
Inherited from java.io.Writer:
lock

Constructor Summary

AccessConstructor and Description
public
WriteBehindStateWriter(Writer out, FacesContext context, int bufSize)

Method Summary

Modifier and TypeMethod and Description
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
flushToWriter()

Write directly from our FastStringWriter to the provided writer.

public static ViewHandlerImpl.WriteBehindStateWriter
private static int
getNextDelimiterIndex(StringBuilder builder, int offset)

public void
public boolean
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.
public void
Inherited from java.io.Writer:
appendappendappendnullWriter

Field Detail

bufback to summary
private char[] buf
bufSizeback to summary
private int bufSize
contextback to summary
private FacesContext context
CUR_WRITERback to summary
private static final ThreadLocal<ViewHandlerImpl.WriteBehindStateWriter> CUR_WRITER
fWriterback to summary
private FastStringWriter fWriter
origback to summary
private Writer orig
outback to summary
private Writer out
STATE_MARKER_LENback to summary
private static final int STATE_MARKER_LEN
stateWrittenback to summary
private boolean stateWritten

Constructor Detail

WriteBehindStateWriterback to summary
public WriteBehindStateWriter(Writer out, FacesContext context, int bufSize)

Method Detail

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
flushToWriterback to summary
public void flushToWriter() throws IOException

Write directly from our FastStringWriter to the provided writer.

Exceptions
IOException:
if an error occurs
getCurrentInstanceback to summary
public static ViewHandlerImpl.WriteBehindStateWriter getCurrentInstance()
getNextDelimiterIndexback to summary
private static int getNextDelimiterIndex(StringBuilder builder, int offset)
releaseback to summary
public void release()
stateWrittenback to summary
public boolean stateWritten()
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
writingStateback to summary
public void writingState()