Class MultiViewHandler
public class MultiViewHandler extends ViewHandler
ViewHandler implementation handles both JSP-based and Facelets/PDL-based views.-
Field Summary
Fields inherited from class jakarta.faces.application.ViewHandler
CHARACTER_ENCODING_KEY, DEFAULT_FACELETS_SUFFIX, DEFAULT_SUFFIX, DEFAULT_SUFFIX_PARAM_NAME, DISABLE_FACELET_JSF_VIEWHANDLER_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
Constructors Constructor Description MultiViewHandler() -
Method Summary
Modifier and Type Method Description voidaddProtectedView(String urlPattern)Add the argumenturlPatternto the thread safeSetof protected views for this application.protected voidaddViewParameters(FacesContext ctx, String viewId, Map<String,List<String>> existingParameters)LocalecalculateLocale(FacesContext context)This code is currently common to allViewHandlingStrategyinstances.StringcalculateRenderKitId(FacesContext context)This code is currently common to allViewHandlingStrategyinstances.protected StringconvertViewId(FacesContext context, String viewId)Adjust the viewID per the requirements ofrenderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot).UIViewRootcreateView(FacesContext context, String viewId)Derive the physical view ID (i.e.StringderiveLogicalViewId(FacesContext context, String requestViewId)Derive and return the viewId from the current request, or the argument input by following the algorithm defined in specification section 7.6.2.protected StringderivePhysicalViewId(FacesContext ctx, String requestViewId, boolean checkPhysical)StringderiveViewId(FacesContext context, String requestViewId)Derive and return the viewId from the current request, or the argument input by following the algorithm defined in specification section 7.6.2.protected LocalefindMatch(FacesContext context, Locale pref)Attempts to find a matching locale based onprefand list of supported locales, using the matching algorithm as described in JSTL 8.3.2.StringgetActionURL(FacesContext context, String viewId)This code is currently common to allViewHandlingStrategyinstances.StringgetBookmarkableURL(FacesContext context, String viewId, Map<String,List<String>> parameters, boolean includeViewParams)Return a Jakarta Server Faces action URL derived from the viewId argument that is suitable to be used as the target of a link in a Jakarta Server Faces response.protected Map<String,List<String>>getFullParameterList(FacesContext ctx, String viewId, Map<String,List<String>> existingParameters)Set<String>getProtectedViewsUnmodifiable()Return an unmodifiableSetof the protected views currently known to thisViewHandlerinstance.StringgetRedirectURL(FacesContext context, String viewId, Map<String,List<String>> parameters, boolean includeViewParams)Return a Jakarta Server Faces action URL derived from theviewIdargument that is suitable to be used by theNavigationHandlerto issue a redirect request to the URL using a NonFaces request.StringgetResourceURL(FacesContext context, String path)This code is currently common to allViewHandlingStrategyinstances.ViewDeclarationLanguagegetViewDeclarationLanguage(FacesContext context, String viewId)Stream<String>getViews(FacesContext context, String path, int maxDepth, ViewVisitOption... options)Return aStreampossibly lazily populated by walking the view trees of every activeViewDeclarationLanguagerooted at a given initial path.Stream<String>getViews(FacesContext context, String path, ViewVisitOption... options)Return aStreampossibly lazily populated by walking the view trees of every activeViewDeclarationLanguagerooted at a given initial path.StringgetWebsocketURL(FacesContext context, String channel)If the value returned from this method is used as thefileargument 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 thatURLwill select the argumentchannelfor connecting the websocket push channel in the current view.voidinitView(FacesContext context)Call the default implementation ofViewHandler.initView(jakarta.faces.context.FacesContext)protected StringnormalizeRequestURI(String uri, String mapping)If the specified mapping is a prefix mapping, and the provided request URI (usually the value fromExternalContext.getRequestServletPath()) starts withmapping + '/', prune the mapping from the URI and return it, otherwise, return the original URI.booleanremoveProtectedView(String urlPattern)Remove the argumenturlPatternfrom the thread safeSetof protected views for this application, if present in theSet.voidrenderView(FacesContext context, UIViewRoot viewToRender)CallViewDeclarationLanguage.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)if the view can be rendered.UIViewRootrestoreView(FacesContext context, String viewId)protected voidsend404Error(FacesContext context)SendHttpServletResponse.SC_NOT_FOUND(404) to the client.voidwriteState(FacesContext context)This code is currently common to allViewHandlingStrategyinstances.
-
Constructor Details
-
MultiViewHandler
public MultiViewHandler()
-
-
Method Details
-
initView
Call the default implementation ofViewHandler.initView(jakarta.faces.context.FacesContext)- Overrides:
initViewin classViewHandler- Parameters:
context- the Faces context.- Throws:
FacesException- if a problem occurs setting the encoding, such as theUnsupportedEncodingExceptionthrown by the underlying Jakarta Servlet or Portlet technology when the encoding is not supported.- See Also:
ViewHandler.initView(jakarta.faces.context.FacesContext)
-
restoreView
- Specified by:
restoreViewin classViewHandler- Parameters:
context-FacesContextfor the current requestviewId- the view identifier for the current request- Returns:
- the restored view root, or null.
- See Also:
ViewHandler.restoreView(jakarta.faces.context.FacesContext, String)
-
createView
Derive the physical view ID (i.e. the physical resource) and call call
ViewDeclarationLanguage.createView(jakarta.faces.context.FacesContext, String).- Specified by:
createViewin classViewHandler- Parameters:
context- the Faces context.viewId- the view id.- Returns:
- the viewroot.
- See Also:
ViewHandler.restoreView(jakarta.faces.context.FacesContext, String)
-
renderView
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesExceptionCall
ViewDeclarationLanguage.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)if the view can be rendered.- Specified by:
renderViewin classViewHandler- Parameters:
context-FacesContextfor the current requestviewToRender- the view to render- Throws:
IOException- if an input/output error occursFacesException- if a Jakarta Servlet error occurs- See Also:
ViewHandler.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)
-
calculateLocale
This code is currently common to all
ViewHandlingStrategyinstances.- Specified by:
calculateLocalein classViewHandler- Parameters:
context-FacesContextfor the current request- Returns:
- the locale.
- See Also:
ViewHandler.calculateLocale(jakarta.faces.context.FacesContext)
-
calculateRenderKitId
This code is currently common to all
ViewHandlingStrategyinstances.- Specified by:
calculateRenderKitIdin classViewHandler- Parameters:
context-FacesContextfor the current request- Returns:
- the render kit id.
- See Also:
ViewHandler.calculateRenderKitId(jakarta.faces.context.FacesContext)
-
writeState
This code is currently common to all
ViewHandlingStrategyinstances.- Specified by:
writeStatein classViewHandler- Parameters:
context-FacesContextfor the current request- Throws:
IOException- if an input/output error occurs- See Also:
ViewHandler.writeState(jakarta.faces.context.FacesContext)
-
getActionURL
This code is currently common to all
ViewHandlingStrategyinstances.- Specified by:
getActionURLin classViewHandler- Parameters:
context-FacesContextfor this requestviewId- View identifier of the desired view- Returns:
- the action url.
- See Also:
ViewHandler.getActionURL(jakarta.faces.context.FacesContext, String)
-
getResourceURL
This code is currently common to all
ViewHandlingStrategyinstances.- Specified by:
getResourceURLin classViewHandler- Parameters:
context-FacesContextfor the current requestpath- Resource path to convert to a URL- Returns:
- the resource URL.
- See Also:
ViewHandler.getResourceURL(jakarta.faces.context.FacesContext, String)
-
getWebsocketURL
Description copied from class:ViewHandlerIf the value returned from this method is used as the
fileargument 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 thatURLwill select the argumentchannelfor connecting the websocket push channel in the current view. It must match thePushContext.URI_PREFIXof the endpoint.- Specified by:
getWebsocketURLin classViewHandler- Parameters:
context-FacesContextfor the current request.channel- The channel name of the websocket.- Returns:
- the websocket URL.
- See Also:
PushContext.URI_PREFIX
-
getBookmarkableURL
public String getBookmarkableURL(FacesContext context, String viewId, Map<String,List<String>> parameters, boolean includeViewParams)Description copied from class:ViewHandlerReturn a Jakarta Server Faces action URL derived from the viewId argument that is suitable to be used as the target of a link in a Jakarta Server Faces response. Compliant implementations must implement this method as specified in section 7.6.2. The default implementation simply calls through to
ViewHandler.getActionURL(jakarta.faces.context.FacesContext, java.lang.String), passing the argumentscontextandviewId.- Overrides:
getBookmarkableURLin 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:ViewHandlerAdd the argument
urlPatternto the thread safeSetof 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:
addProtectedViewin classViewHandler- Parameters:
urlPattern- the url-pattern to add.
-
getProtectedViewsUnmodifiable
Description copied from class:ViewHandlerReturn an unmodifiable
Setof the protected views currently known to thisViewHandlerinstance. Compliant implementations must return aSetthat 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:
getProtectedViewsUnmodifiablein classViewHandler- Returns:
- the unmodifiable set of protected views.
-
removeProtectedView
Description copied from class:ViewHandlerRemove the argument
urlPatternfrom the thread safeSetof protected views for this application, if present in theSet. If the argumenturlPatternis 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. Returnstrueif thisSetcontained the argument. The default implementation takes no action and returnsfalse.- Overrides:
removeProtectedViewin classViewHandler- Parameters:
urlPattern- the url-pattern to remove.- Returns:
trueif in theSet,falseotherwise.
-
getRedirectURL
public String getRedirectURL(FacesContext context, String viewId, Map<String,List<String>> parameters, boolean includeViewParams)Description copied from class:ViewHandlerReturn a Jakarta Server Faces action URL derived from the
viewIdargument that is suitable to be used by theNavigationHandlerto issue a redirect request to the URL using a NonFaces request. Compliant implementations must implement this method as specified in section 7.6.2. The default implementation simply calls through toViewHandler.getActionURL(jakarta.faces.context.FacesContext, java.lang.String), passing the argumentscontextandviewId.- Overrides:
getRedirectURLin 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:
ViewHandler.getRedirectURL(jakarta.faces.context.FacesContext, String, java.util.Map, boolean)
-
getViewDeclarationLanguage
Description copied from class:ViewHandlerReturn the
ViewDeclarationLanguageinstance used for thisViewHandlerinstance.The default implementation must use
ViewDeclarationLanguageFactory.getViewDeclarationLanguage(java.lang.String)to obtain the appropriateViewDeclarationLanguageimplementation 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:
getViewDeclarationLanguagein classViewHandler- Parameters:
context- theFacesContextfor this request.viewId- the logical view id, as returned fromViewHandler.deriveLogicalViewId(jakarta.faces.context.FacesContext, java.lang.String)for which theViewDeclarationLanguageshould be returned.- Returns:
- the ViewDeclarationLanguage, or null.
- See Also:
ViewHandler.getViewDeclarationLanguage(jakarta.faces.context.FacesContext, String)
-
getViews
Description copied from class:ViewHandlerReturn a
Streampossibly lazily populated by walking the view trees of every activeViewDeclarationLanguagerooted at a given initial path. The view tree of everyViewDeclarationLanguageis 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:
Put differently, it visits all levels of the view tree.getViews(facesContext, start, Integer.MAX_VALUE, options)
In case more than one active
ViewDeclarationLanguageis present, the order in which view ids from eachViewDeclarationLanguageappear in the stream is undetermined, except for the guarantee that every individualViewDeclarationLanguageis traversed breadth-first.- Overrides:
getViewsin classViewHandler- Parameters:
context- TheFacesContextfor this request.path- The initial path from which to start looking for view ids.options- The options to influence the traversal. SeeViewVisitOptionfor details on those.- Returns:
- the
Streamof view ids
-
getViews
public Stream<String> getViews(FacesContext context, String path, int maxDepth, ViewVisitOption... options)Description copied from class:ViewHandlerReturn a
Streampossibly lazily populated by walking the view trees of every activeViewDeclarationLanguagerooted at a given initial path. The view tree of everyViewDeclarationLanguageis individually traversed breadth-first as per the contract ofViewDeclarationLanguage.getViews(FacesContext, String, int, ViewVisitOption...). The elements in the stream are logical view ids.The
maxDepthparameter is the maximum depth of directory levels to visit for eachViewDeclarationLanguagebeyond the initial path, which is always visited. The value is relative to the root (/), not to the given initial path. E.g. givenmaxDepth=3and initial path/foo/, visiting will proceed up to/foo/bar/, where/counts as depth1,/foo/as depth2and/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_VALUEmay be used to indicate that all levels should be visited.In case more than one active
ViewDeclarationLanguageis present, the order in which view ids from eachViewDeclarationLanguageappear in the stream is undetermined, except for the guarantee that every individualViewDeclarationLanguageis traversed breadth-first.- Overrides:
getViewsin classViewHandler- Parameters:
context- TheFacesContextfor 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. SeeViewVisitOptionfor details on those.- Returns:
- the
Streamof view ids
-
deriveViewId
Description copied from class:ViewHandlerDerive and return the viewId from the current request, or the argument input by following the algorithm defined in specification section 7.6.2.
This method should work correctly when the FacesServlet is invoked via either a
path mapping,extension mappingor anexact match(mapping) as defined by Servlet.12.2. Note thatpath mappingis also commonly known as prefix mapping (e.g. "/faces/*") andextension mappingas suffix mapping (e.g. "*.xhtml"). Anexact matchis 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:
deriveViewIdin classViewHandler- Parameters:
context- theFacesContextfor this requestrequestViewId- theviewIdto derive,- Returns:
- the derived view id.
-
deriveLogicalViewId
Description copied from class:ViewHandlerDerive and return the viewId from the current request, or the argument input by following the algorithm defined in specification section 7.6.2. 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 mappingor anexact match(mapping) as defined by Servlet.12.2. Note thatpath mappingis also commonly known as prefix mapping (e.g. "/faces/*") andextension mappingas suffix mapping (e.g. "*.xhtml"). Anexact matchis 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:
deriveLogicalViewIdin classViewHandler- Parameters:
context- theFacesContextfor this requestrequestViewId- theviewIdto derive,- Returns:
- the derived logical view id.
-
normalizeRequestURI
If the specified mapping is a prefix mapping, and the provided request URI (usually the value from
ExternalContext.getRequestServletPath()) starts withmapping + '/', prune the mapping from the URI and return it, otherwise, return the original URI.- Parameters:
uri- the servlet request pathmapping- the FacesServlet mapping used for this request- Returns:
- the URI without additional FacesServlet mappings
- Since:
- 1.2
-
convertViewId
Adjust the viewID per the requirements of
renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot).- Parameters:
context- currentFacesContextviewId- incoming view ID- Returns:
- the view ID with an altered suffix mapping (if necessary)
-
derivePhysicalViewId
protected String derivePhysicalViewId(FacesContext ctx, String requestViewId, boolean checkPhysical) -
getFullParameterList
-
addViewParameters
-
findMatch
Attempts to find a matching locale based onprefand list of supported locales, using the matching algorithm as described in JSTL 8.3.2.- Parameters:
context- theFacesContextfor 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- theFacesContextfor the current request
-