ViewHandler
implementation handles the Facelets VDL-based views.-
Field Summary
Fields inherited from class jakarta.faces.application.ViewHandler
CHARACTER_ENCODING_KEY, DEFAULT_FACELETS_SUFFIX, DEFAULT_SUFFIX, DEFAULT_SUFFIX_PARAM_NAME, FACELETS_BUFFER_SIZE_PARAM_NAME, FACELETS_DECORATORS_PARAM_NAME, FACELETS_LIBRARIES_PARAM_NAME, FACELETS_REFRESH_PERIOD_PARAM_NAME, FACELETS_SKIP_COMMENTS_PARAM_NAME, FACELETS_SUFFIX_PARAM_NAME, FACELETS_VIEW_MAPPINGS_PARAM_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addProtectedView
(String urlPattern) Add the argumenturlPattern
to the thread safeSet
of protected views for this application.protected void
addViewParameters
(FacesContext ctx, String viewId, Map<String, List<String>> existingParameters) calculateLocale
(FacesContext context) This code is currently common to allViewHandlingStrategy
instances.calculateRenderKitId
(FacesContext context) This code is currently common to allViewHandlingStrategy
instances.protected String
convertViewId
(FacesContext context, String viewId) Adjust the viewID per the requirements ofrenderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)
.createView
(FacesContext context, String viewId) Derive the physical view ID (i.e.deriveLogicalViewId
(FacesContext context, String requestViewId) Derive and return the viewId from the current request, or the argument input by following the algorithm defined in section 7.6.2 "Default ViewHandler Implementation" of the Jakarta Faces Specification Document.protected String
derivePhysicalViewId
(FacesContext ctx, String requestViewId, boolean checkPhysical) deriveViewId
(FacesContext context, String requestViewId) Derive and return the viewId from the current request, or the argument input by following the algorithm defined in section 7.6.2 "Default ViewHandler Implementation" of the Jakarta Faces Specification Document.protected Locale
findMatch
(FacesContext context, Locale pref) Attempts to find a matching locale based onpref
and list of supported locales, using the matching algorithm as described in JSTL 8.3.2.getActionURL
(FacesContext context, String viewId) This code is currently common to allViewHandlingStrategy
instances.getBookmarkableURL
(FacesContext context, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) Return a Jakarta Faces action URL derived from the viewId argument that is suitable to be used as the target of a link in a Jakarta Faces response.getFullParameterList
(FacesContext ctx, String viewId, Map<String, List<String>> existingParameters) Return an unmodifiableSet
of the protected views currently known to thisViewHandler
instance.getRedirectURL
(FacesContext context, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) Return a Jakarta Faces action URL derived from theviewId
argument that is suitable to be used by theNavigationHandler
to issue a redirect request to the URL using a NonFaces request.getResourceURL
(FacesContext context, String path) This code is currently common to allViewHandlingStrategy
instances.getViewDeclarationLanguage
(FacesContext context, String viewId) getViews
(FacesContext context, String path, int maxDepth, ViewVisitOption... options) Return aStream
possibly lazily populated by walking the view trees of every activeViewDeclarationLanguage
rooted at a given initial path.getViews
(FacesContext context, String path, ViewVisitOption... options) Return aStream
possibly lazily populated by walking the view trees of every activeViewDeclarationLanguage
rooted at a given initial path.getWebsocketURL
(FacesContext context, String channel) If the value returned from this method is used as thefile
argument to the four-argument constructor forjava.net.URL
(assuming appropriate values are used for the first three arguments), then a client making a push handshake request to thetoExternalForm()
of thatURL
will select the argumentchannel
for connecting the websocket push channel in the current view.void
initView
(FacesContext context) Call the default implementation ofViewHandler.initView(jakarta.faces.context.FacesContext)
protected String
normalizeRequestURI
(String viewId, String mapping) If the specified mapping is a prefix mapping, and the provided request URI (sometimes the value fromExternalContext.getRequestServletPath()
) starts withmapping
, prune the mapping from the URI and return it, otherwise, return the original URI.boolean
removeProtectedView
(String urlPattern) Remove the argumenturlPattern
from the thread safeSet
of protected views for this application, if present in theSet
.void
renderView
(FacesContext context, UIViewRoot viewToRender) CallViewDeclarationLanguage.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)
if the view can be rendered.restoreView
(FacesContext context, String viewId) protected void
send404Error
(FacesContext context) SendHttpServletResponse.SC_NOT_FOUND
(404) to the client.void
writeState
(FacesContext context) This code is currently common to allViewHandlingStrategy
instances.Methods inherited from class jakarta.faces.application.ViewHandler
calculateCharacterEncoding
-
Constructor Details
-
MultiViewHandler
public MultiViewHandler()
-
-
Method Details
-
initView
Call the default implementation ofViewHandler.initView(jakarta.faces.context.FacesContext)
- Overrides:
initView
in classViewHandler
- Parameters:
context
- the Faces context.- Throws:
FacesException
- if a problem occurs setting the encoding, such as theUnsupportedEncodingException
thrown by the underlying Jakarta Servlet or Portlet technology when the encoding is not supported.- See Also:
-
restoreView
- Specified by:
restoreView
in classViewHandler
- Parameters:
context
-FacesContext
for the current requestviewId
- the view identifier for the current request- Returns:
- the restored view root, or null.
- See Also:
-
createView
Derive the physical view ID (i.e. the physical resource) and call call
ViewDeclarationLanguage.createView(jakarta.faces.context.FacesContext, String)
.- Specified by:
createView
in classViewHandler
- Parameters:
context
- the Faces context.viewId
- the view id.- Returns:
- the viewroot.
- See Also:
-
renderView
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException Call
ViewDeclarationLanguage.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)
if the view can be rendered.- Specified by:
renderView
in classViewHandler
- Parameters:
context
-FacesContext
for the current requestviewToRender
- the view to render- Throws:
IOException
- if an input/output error occursFacesException
- if a Jakarta Servlet error occurs- See Also:
-
calculateLocale
This code is currently common to all
ViewHandlingStrategy
instances.- Specified by:
calculateLocale
in classViewHandler
- Parameters:
context
-FacesContext
for the current request- Returns:
- the locale.
- See Also:
-
calculateRenderKitId
This code is currently common to all
ViewHandlingStrategy
instances.- Specified by:
calculateRenderKitId
in classViewHandler
- Parameters:
context
-FacesContext
for the current request- Returns:
- the render kit id.
- See Also:
-
writeState
This code is currently common to all
ViewHandlingStrategy
instances.- Specified by:
writeState
in classViewHandler
- Parameters:
context
-FacesContext
for the current request- Throws:
IOException
- if an input/output error occurs- See Also:
-
getActionURL
This code is currently common to all
ViewHandlingStrategy
instances.- Specified by:
getActionURL
in classViewHandler
- Parameters:
context
-FacesContext
for this requestviewId
- View identifier of the desired view- Returns:
- the action url.
- See Also:
-
getResourceURL
This code is currently common to all
ViewHandlingStrategy
instances.- Specified by:
getResourceURL
in classViewHandler
- Parameters:
context
-FacesContext
for the current requestpath
- Resource path to convert to a URL- Returns:
- the resource URL.
- See Also:
-
getWebsocketURL
Description copied from class:ViewHandler
If the value returned from this method is used as the
file
argument to the four-argument constructor forjava.net.URL
(assuming appropriate values are used for the first three arguments), then a client making a push handshake request to thetoExternalForm()
of thatURL
will select the argumentchannel
for connecting the websocket push channel in the current view. It must match thePushContext.URI_PREFIX
of the endpoint.- Specified by:
getWebsocketURL
in classViewHandler
- Parameters:
context
-FacesContext
for the current request.channel
- The channel name of the websocket.- Returns:
- the websocket URL.
- See Also:
-
getBookmarkableURL
public String getBookmarkableURL(FacesContext context, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) Description copied from class:ViewHandler
Return a Jakarta Faces action URL derived from the viewId argument that is suitable to be used as the target of a link in a Jakarta Faces response. Compliant implementations must implement this method as specified in section 7.6.2 "Default ViewHandler Implementation" of the Jakarta Faces Specification Document. The default implementation simply calls through to
ViewHandler.getActionURL(jakarta.faces.context.FacesContext, java.lang.String)
, passing the argumentscontext
andviewId
.- Overrides:
getBookmarkableURL
in classViewHandler
- Parameters:
context
- The FacesContext processing this requestviewId
- The view identifier of the target pageparameters
- A mapping of parameter names to one or more valuesincludeViewParams
- A flag indicating whether view parameters should be encoded into this URL- Returns:
- the bookmarkable URL.
-
addProtectedView
Description copied from class:ViewHandler
Add the argument
urlPattern
to the thread safeSet
of protected views for this application. Compliant implementations make it so a subsequent call toViewHandler.getProtectedViewsUnmodifiable()
contains the argument. The runtime must support calling this method at any time after application startup. The default implementation takes no action.- Overrides:
addProtectedView
in classViewHandler
- Parameters:
urlPattern
- the url-pattern to add.
-
getProtectedViewsUnmodifiable
Description copied from class:ViewHandler
Return an unmodifiable
Set
of the protected views currently known to thisViewHandler
instance. Compliant implementations must return aSet
that is the concatenation of the contents of all the<url-pattern>
elements within all the<protected-views>
in all of the application configuration resources in the current application. The runtime must support calling this method at any time after application startup. The default implementation returns an unmodifiable emptySet
.- Overrides:
getProtectedViewsUnmodifiable
in classViewHandler
- Returns:
- the unmodifiable set of protected views.
-
removeProtectedView
Description copied from class:ViewHandler
Remove the argument
urlPattern
from the thread safeSet
of protected views for this application, if present in theSet
. If the argumenturlPattern
is not present in theSet
, this method has no effect. Compliant implementations must make it so a subsequent call toViewHandler.getProtectedViewsUnmodifiable()
does not contain the argument. The runtime must support calling this method at any time after application startup. Returnstrue
if thisSet
contained the argument. The default implementation takes no action and returnsfalse
.- Overrides:
removeProtectedView
in classViewHandler
- Parameters:
urlPattern
- the url-pattern to remove.- Returns:
true
if in theSet
,false
otherwise.
-
getRedirectURL
public String getRedirectURL(FacesContext context, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) Description copied from class:ViewHandler
Return a Jakarta Faces action URL derived from the
viewId
argument that is suitable to be used by theNavigationHandler
to issue a redirect request to the URL using a NonFaces request. Compliant implementations must implement this method as specified in section 7.6.2 "Default ViewHandler Implementation" of the Jakarta Faces Specification Document. The default implementation simply calls through toViewHandler.getActionURL(jakarta.faces.context.FacesContext, java.lang.String)
, passing the argumentscontext
andviewId
.- Overrides:
getRedirectURL
in classViewHandler
- Parameters:
context
- The FacesContext processing this requestviewId
- The view identifier of the target pageparameters
- A mapping of parameter names to one or more valuesincludeViewParams
- A flag indicating whether view parameters should be encoded into this URL- Returns:
- the redirect URL.
- See Also:
-
getViewDeclarationLanguage
Description copied from class:ViewHandler
Return the
ViewDeclarationLanguage
instance used for thisViewHandler
instance.The default implementation must use
ViewDeclarationLanguageFactory.getViewDeclarationLanguage(java.lang.String)
to obtain the appropriateViewDeclarationLanguage
implementation for the argumentviewId
. Any exceptions thrown as a result of invoking that method must not be swallowed.The default implementation of this method returns null.
- Overrides:
getViewDeclarationLanguage
in classViewHandler
- Parameters:
context
- theFacesContext
for this request.viewId
- the logical view id, as returned fromViewHandler.deriveLogicalViewId(jakarta.faces.context.FacesContext, java.lang.String)
for which theViewDeclarationLanguage
should be returned.- Returns:
- the ViewDeclarationLanguage, or null.
- See Also:
-
getViews
Description copied from class:ViewHandler
Return a
Stream
possibly lazily populated by walking the view trees of every activeViewDeclarationLanguage
rooted at a given initial path. The view tree of everyViewDeclarationLanguage
is individually traversed breadth-first as per the contract ofViewDeclarationLanguage.getViews(FacesContext, String, int, ViewVisitOption...)
. The elements in the stream are logical view ids.This method works as if invoking it were equivalent to evaluating the expression:
getViews(facesContext, start, Integer.MAX_VALUE, options)
In case more than one active
ViewDeclarationLanguage
is present, the order in which view ids from eachViewDeclarationLanguage
appear in the stream is undetermined, except for the guarantee that every individualViewDeclarationLanguage
is traversed breadth-first.- Overrides:
getViews
in classViewHandler
- Parameters:
context
- TheFacesContext
for this request.path
- The initial path from which to start looking for view ids.options
- The options to influence the traversal. SeeViewVisitOption
for details on those.- Returns:
- the
Stream
of view ids
-
getViews
public Stream<String> getViews(FacesContext context, String path, int maxDepth, ViewVisitOption... options) Description copied from class:ViewHandler
Return a
Stream
possibly lazily populated by walking the view trees of every activeViewDeclarationLanguage
rooted at a given initial path. The view tree of everyViewDeclarationLanguage
is individually traversed breadth-first as per the contract ofViewDeclarationLanguage.getViews(FacesContext, String, int, ViewVisitOption...)
. The elements in the stream are logical view ids.The
maxDepth
parameter is the maximum depth of directory levels to visit for eachViewDeclarationLanguage
beyond the initial path, which is always visited. The value is relative to the root (/
), not to the given initial path. E.g. givenmaxDepth
=3
and initial path/foo/
, visiting will proceed up to/foo/bar/
, where/
counts as depth1
,/foo/
as depth2
and/foo/bar/
as depth3
. A value lower or equal to the depth of the initial path means that only the initial path is visited. A value ofMAX_VALUE
may be used to indicate that all levels should be visited.In case more than one active
ViewDeclarationLanguage
is present, the order in which view ids from eachViewDeclarationLanguage
appear in the stream is undetermined, except for the guarantee that every individualViewDeclarationLanguage
is traversed breadth-first.- Overrides:
getViews
in classViewHandler
- Parameters:
context
- TheFacesContext
for this request.path
- The initial path from which to start looking for view ids.maxDepth
- The absolute maximum depth of nested directories to visit counted from the root (/
).options
- The options to influence the traversal. SeeViewVisitOption
for details on those.- Returns:
- the
Stream
of view ids
-
deriveViewId
Description copied from class:ViewHandler
Derive and return the viewId from the current request, or the argument input by following the algorithm defined in section 7.6.2 "Default ViewHandler Implementation" of the Jakarta Faces Specification Document.
This method should work correctly when the FacesServlet is invoked via either a
path mapping
,extension mapping
or anexact match
(mapping) as defined by Servlet.12.2. Note thatpath mapping
is also commonly known as prefix mapping (e.g. "/faces/*") andextension mapping
as suffix mapping (e.g. "*.xhtml"). Anexact match
is possible where there's a servlet mapping with an exact URL pattern such as "/foo".The default implementation of this method simply returns requestViewId unchanged.
- Overrides:
deriveViewId
in classViewHandler
- Parameters:
context
- theFacesContext
for this requestrequestViewId
- theviewId
to derive,- Returns:
- the derived view id.
-
deriveLogicalViewId
Description copied from class:ViewHandler
Derive and return the viewId from the current request, or the argument input by following the algorithm defined in section 7.6.2 "Default ViewHandler Implementation" of the Jakarta Faces Specification Document. Note that unlike
deriveViewId()
, this method does not require that a physical view be present.This method should work correctly when the FacesServlet is invoked via either a
path mapping
,extension mapping
or anexact match
(mapping) as defined by Servlet.12.2. Note thatpath mapping
is also commonly known as prefix mapping (e.g. "/faces/*") andextension mapping
as suffix mapping (e.g. "*.xhtml"). Anexact match
is possible where there's a servlet mapping with an exact URL pattern such as "/foo".The default implementation of this method simply returns requestViewId unchanged.
- Overrides:
deriveLogicalViewId
in classViewHandler
- Parameters:
context
- theFacesContext
for this requestrequestViewId
- theviewId
to derive,- Returns:
- the derived logical view id.
-
derivePhysicalViewId
protected String derivePhysicalViewId(FacesContext ctx, String requestViewId, boolean checkPhysical) -
normalizeRequestURI
If the specified mapping is a prefix mapping, and the provided request URI (sometimes the value from
ExternalContext.getRequestServletPath()
) starts withmapping
, prune the mapping from the URI and return it, otherwise, return the original URI.- Parameters:
viewId
- something resembling a view id, can come from the request or from the navigation handler.mapping
- the FacesServlet mapping used for this request with the "/*" removed, e.g. /faces instead of /faces/*- Returns:
- the viewId without additional prefix FacesServlet mappings
- Since:
- 1.2
-
convertViewId
Adjust the viewID per the requirements of
renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)
.- Parameters:
context
- currentFacesContext
viewId
- incoming view ID- Returns:
- the view ID with an altered suffix mapping (if necessary)
-
getFullParameterList
-
addViewParameters
-
findMatch
Attempts to find a matching locale based onpref
and list of supported locales, using the matching algorithm as described in JSTL 8.3.2.- Parameters:
context
- theFacesContext
for the current requestpref
- the preferred locale- Returns:
- the Locale based on pref and the matching alogritm specified in JSTL 8.3.2
-
send404Error
Send
HttpServletResponse.SC_NOT_FOUND
(404) to the client.- Parameters:
context
- theFacesContext
for the current request
-