Package org.omnifaces.resourcehandler
Class ViewResourceHandler
- java.lang.Object
- 
- jakarta.faces.application.ResourceHandler
- 
- jakarta.faces.application.ResourceHandlerWrapper
- 
- org.omnifaces.resourcehandler.DefaultResourceHandler
- 
- org.omnifaces.resourcehandler.ViewResourceHandler
 
 
 
 
- 
- All Implemented Interfaces:
- FacesWrapper<ResourceHandler>
 
 public class ViewResourceHandler extends DefaultResourceHandler ThisResourceHandlerbasically turns any concrete non-Facelets file into a Faces view, so that you can use EL expressions and even Faces components in them. The response content type will default toFaces.getMimeType(String)which is configureable inweb.xmland overrideable via<f:view contentType="...">.Real world examples are /sitemap.xmland/robots.txt.InstallationTo get it to run, this handler needs be registered as follows in faces-config.xml:<application> <resource-handler>org.omnifaces.resourcehandler.ViewResourceHandler</resource-handler> </application>To configure the Faces view resources, a "org.omnifaces.VIEW_RESOURCE_HANDLER_URIS" context parameter has to be provided wherein the view resources are specified as a comma separated string of context-relative URIs. Here is an example configuration: <context-param> <param-name>org.omnifaces.VIEW_RESOURCE_HANDLER_URIS</param-name> <param-value>/sitemap.xml, /products/sitemap.xml, /reviews/sitemap.xml, /robots.txt</param-value> </context-param>Wildcards in URIs are at the moment not supported. The OmniViewHandlerwill take care of rendering the view.- Since:
- 3.10
- Author:
- Bauke Scholtz
- See Also:
- DefaultResourceHandler,- OmniViewHandler
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringPARAM_NAME_VIEW_RESOURCESThe context parameter name to specify URIs to treat as Faces views.- 
Fields inherited from class org.omnifaces.resourcehandler.DefaultResourceHandlerFACES_SCRIPT_RESOURCE_NAME, RES_NOT_FOUND
 - 
Fields inherited from class jakarta.faces.application.ResourceHandlerJSF_SCRIPT_LIBRARY_NAME, JSF_SCRIPT_RESOURCE_NAME, LOCALE_PREFIX, RESOURCE_CONTRACT_XML, RESOURCE_EXCLUDES_DEFAULT_VALUE, RESOURCE_EXCLUDES_PARAM_NAME, RESOURCE_IDENTIFIER, WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME, WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME
 
- 
 - 
Constructor SummaryConstructors Constructor Description ViewResourceHandler(ResourceHandler wrapped)Creates a new instance of this view resource handler which wraps the given resource handler.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddFacesServletMappingsIfNecessary(ServletContext servletContext)This will map theFacesServletto the URIs specified in "org.omnifaces.VIEW_RESOURCE_HANDLER_URIS" context parameter.ViewResourcecreateViewResource(FacesContext context, String resourceName)This override ensures thatFaces.getRequestServletPath()is returned as concrete resource rather than the providedresourceNamewhen theisViewResourceRequest(FacesContext)returns true.static booleanisViewResourceRequest(FacesContext context)Returnstrueif the current HTTP request is requesting for a view resource managed by this resource handler.- 
Methods inherited from class org.omnifaces.resourcehandler.DefaultResourceHandlercreateResource, createResource, createResource, createResourceFromLibrary, decorateResource, decorateResource, getLibraryName
 - 
Methods inherited from class jakarta.faces.application.ResourceHandlerWrappercreateResourceFromId, getRendererTypeForResourceName, getViewResources, getViewResources, getWrapped, handleResourceRequest, isResourceRendered, isResourceRequest, isResourceURL, libraryExists, markResourceRendered
 
- 
 
- 
- 
- 
Field Detail- 
PARAM_NAME_VIEW_RESOURCESpublic static final String PARAM_NAME_VIEW_RESOURCES The context parameter name to specify URIs to treat as Faces views.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
ViewResourceHandlerpublic ViewResourceHandler(ResourceHandler wrapped) Creates a new instance of this view resource handler which wraps the given resource handler.- Parameters:
- wrapped- The resource handler to be wrapped.
 
 
- 
 - 
Method Detail- 
addFacesServletMappingsIfNecessarypublic static void addFacesServletMappingsIfNecessary(ServletContext servletContext) throws MalformedURLException This will map theFacesServletto the URIs specified in "org.omnifaces.VIEW_RESOURCE_HANDLER_URIS" context parameter. This is invoked byApplicationListener, because the faces servlet registration has to be available for adding new mappings.- Parameters:
- servletContext- The involved servlet context.
- Throws:
- MalformedURLException- When one of the URIs specified in context parameter is malformed.
 
 - 
isViewResourceRequestpublic static boolean isViewResourceRequest(FacesContext context) Returnstrueif the current HTTP request is requesting for a view resource managed by this resource handler.- Parameters:
- context- The involved faces context.
- Returns:
- trueif the current HTTP request is requesting for a view resource managed by this resource handler.
 
 - 
createViewResourcepublic ViewResource createViewResource(FacesContext context, String resourceName) This override ensures thatFaces.getRequestServletPath()is returned as concrete resource rather than the providedresourceNamewhen theisViewResourceRequest(FacesContext)returns true.- Overrides:
- createViewResourcein class- ResourceHandlerWrapper
 
 
- 
 
-