Class MultiViewHandler
public class MultiViewHandler extends ViewHandler
ViewHandler implementation handles both JSP-based and Facelets/PDL-based views.- 
Field SummaryFields inherited from class jakarta.faces.application.ViewHandlerCHARACTER_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 SummaryConstructors Constructor Description MultiViewHandler()
- 
Method SummaryModifier 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- 
MultiViewHandlerpublic MultiViewHandler()
 
- 
- 
Method Details- 
initViewCall the default implementation ofViewHandler.initView(jakarta.faces.context.FacesContext)- Overrides:
- initViewin class- ViewHandler
- Parameters:
- context- the Faces context.
- Throws:
- FacesException- if a problem occurs setting the encoding, such as the- UnsupportedEncodingExceptionthrown 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 class- ViewHandler
- Parameters:
- context-- FacesContextfor the current request
- viewId- the view identifier for the current request
- Returns:
- the restored view root, or null.
- See Also:
- ViewHandler.restoreView(jakarta.faces.context.FacesContext, String)
 
- 
createViewDerive the physical view ID (i.e. the physical resource) and call call ViewDeclarationLanguage.createView(jakarta.faces.context.FacesContext, String).- Specified by:
- createViewin class- ViewHandler
- Parameters:
- context- the Faces context.
- viewId- the view id.
- Returns:
- the viewroot.
- See Also:
- ViewHandler.restoreView(jakarta.faces.context.FacesContext, String)
 
- 
renderViewpublic 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 class- ViewHandler
- Parameters:
- context-- FacesContextfor the current request
- viewToRender- the view to render
- Throws:
- IOException- if an input/output error occurs
- FacesException- if a Jakarta Servlet error occurs
- See Also:
- ViewHandler.renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot)
 
- 
calculateLocaleThis code is currently common to all ViewHandlingStrategyinstances.- Specified by:
- calculateLocalein class- ViewHandler
- Parameters:
- context-- FacesContextfor the current request
- Returns:
- the locale.
- See Also:
- ViewHandler.calculateLocale(jakarta.faces.context.FacesContext)
 
- 
calculateRenderKitIdThis code is currently common to all ViewHandlingStrategyinstances.- Specified by:
- calculateRenderKitIdin class- ViewHandler
- Parameters:
- context-- FacesContextfor the current request
- Returns:
- the render kit id.
- See Also:
- ViewHandler.calculateRenderKitId(jakarta.faces.context.FacesContext)
 
- 
writeStateThis code is currently common to all ViewHandlingStrategyinstances.- Specified by:
- writeStatein class- ViewHandler
- Parameters:
- context-- FacesContextfor the current request
- Throws:
- IOException- if an input/output error occurs
- See Also:
- ViewHandler.writeState(jakarta.faces.context.FacesContext)
 
- 
getActionURLThis code is currently common to all ViewHandlingStrategyinstances.- Specified by:
- getActionURLin class- ViewHandler
- Parameters:
- context-- FacesContextfor this request
- viewId- View identifier of the desired view
- Returns:
- the action url.
- See Also:
- ViewHandler.getActionURL(jakarta.faces.context.FacesContext, String)
 
- 
getResourceURLThis code is currently common to all ViewHandlingStrategyinstances.- Specified by:
- getResourceURLin class- ViewHandler
- Parameters:
- context-- FacesContextfor the current request
- path- Resource path to convert to a URL
- Returns:
- the resource URL.
- See Also:
- ViewHandler.getResourceURL(jakarta.faces.context.FacesContext, String)
 
- 
getWebsocketURLDescription 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 class- ViewHandler
- Parameters:
- context-- FacesContextfor the current request.
- channel- The channel name of the websocket.
- Returns:
- the websocket URL.
- See Also:
- PushContext.URI_PREFIX
 
- 
getBookmarkableURLpublic 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 class- ViewHandler
- Parameters:
- context- The FacesContext processing this request
- viewId- The view identifier of the target page
- parameters- A mapping of parameter names to one or more values
- includeViewParams- A flag indicating whether view parameters should be encoded into this URL
- Returns:
- the bookmarkable URL.
 
- 
addProtectedViewDescription 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 class- ViewHandler
- Parameters:
- urlPattern- the url-pattern to add.
 
- 
getProtectedViewsUnmodifiableDescription 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 class- ViewHandler
- Returns:
- the unmodifiable set of protected views.
 
- 
removeProtectedViewDescription 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 class- ViewHandler
- Parameters:
- urlPattern- the url-pattern to remove.
- Returns:
- trueif in the- Set,- falseotherwise.
 
- 
getRedirectURLpublic 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 class- ViewHandler
- Parameters:
- context- The FacesContext processing this request
- viewId- The view identifier of the target page
- parameters- A mapping of parameter names to one or more values
- includeViewParams- 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)
 
- 
getViewDeclarationLanguageDescription 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 class- ViewHandler
- Parameters:
- context- the- FacesContextfor this request.
- viewId- the logical view id, as returned from- ViewHandler.deriveLogicalViewId(jakarta.faces.context.FacesContext, java.lang.String)for which the- ViewDeclarationLanguageshould be returned.
- Returns:
- the ViewDeclarationLanguage, or null.
- See Also:
- ViewHandler.getViewDeclarationLanguage(jakarta.faces.context.FacesContext, String)
 
- 
getViewsDescription 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 class- ViewHandler
- Parameters:
- context- The- FacesContextfor this request.
- path- The initial path from which to start looking for view ids.
- options- The options to influence the traversal. See- ViewVisitOptionfor details on those.
- Returns:
- the Streamof view ids
 
- 
getViewspublic 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 class- ViewHandler
- Parameters:
- context- The- FacesContextfor 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. See- ViewVisitOptionfor details on those.
- Returns:
- the Streamof view ids
 
- 
deriveViewIdDescription 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 class- ViewHandler
- Parameters:
- context- the- FacesContextfor this request
- requestViewId- the- viewIdto derive,
- Returns:
- the derived view id.
 
- 
deriveLogicalViewIdDescription 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 class- ViewHandler
- Parameters:
- context- the- FacesContextfor this request
- requestViewId- the- viewIdto derive,
- Returns:
- the derived logical view id.
 
- 
normalizeRequestURIIf 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 path
- mapping- the FacesServlet mapping used for this request
- Returns:
- the URI without additional FacesServlet mappings
- Since:
- 1.2
 
- 
convertViewIdAdjust the viewID per the requirements of renderView(jakarta.faces.context.FacesContext, jakarta.faces.component.UIViewRoot).- Parameters:
- context- current- FacesContext
- viewId- incoming view ID
- Returns:
- the view ID with an altered suffix mapping (if necessary)
 
- 
derivePhysicalViewIdprotected String derivePhysicalViewId(FacesContext ctx, String requestViewId, boolean checkPhysical)
- 
getFullParameterList
- 
addViewParameters
- 
findMatchAttempts to find a matching locale based onprefand list of supported locales, using the matching algorithm as described in JSTL 8.3.2.- Parameters:
- context- the- FacesContextfor the current request
- pref- the preferred locale
- Returns:
- the Locale based on pref and the matching alogritm specified in JSTL 8.3.2
 
- 
send404ErrorSend HttpServletResponse.SC_NOT_FOUND(404) to the client.- Parameters:
- context- the- FacesContextfor the current request
 
 
-