public class ViewResourceHandler extends DefaultResourceHandler
ResourceHandler
basically turns any concrete non-Facelets file into a JSF view, so that you can use EL expressions and even JSF components in them.
The response content type will default to Faces.getMimeType(String)
which is configureable in web.xml
and overrideable via <f:view contentType="...">
.
Real world examples are /sitemap.xml
and /robots.txt
.
To 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 JSF 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 OmniViewHandler
will take care of rendering the view.
DefaultResourceHandler
,
OmniViewHandler
Modifier and Type | Field and Description |
---|---|
static String |
PARAM_NAME_VIEW_RESOURCES
The context parameter name to specify URIs to treat as JSF views.
|
RES_NOT_FOUND
JSF_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 and Description |
---|
ViewResourceHandler(ResourceHandler wrapped)
Creates a new instance of this view resource handler which wraps the given resource handler.
|
Modifier and Type | Method and Description |
---|---|
static void |
addFacesServletMappingsIfNecessary(ServletContext servletContext)
This will map the
FacesServlet to the URIs specified in "org.omnifaces.VIEW_RESOURCE_HANDLER_URIS"
context parameter. |
ViewResource |
createViewResource(FacesContext context,
String resourceName)
This override ensures that
Faces.getRequestServletPath() is returned as concrete resource rather than the provided resourceName
when the isViewResourceRequest(FacesContext) returns true. |
static boolean |
isViewResourceRequest(FacesContext context)
Returns
true if the current HTTP request is requesting for a view resource managed by this resource handler. |
createResource, createResource, createResource, createResourceFromLibrary, decorateResource, decorateResource, getLibraryName
createResourceFromId, getRendererTypeForResourceName, getViewResources, getViewResources, getWrapped, handleResourceRequest, isResourceRendered, isResourceRequest, isResourceURL, libraryExists, markResourceRendered
public static final String PARAM_NAME_VIEW_RESOURCES
public ViewResourceHandler(ResourceHandler wrapped)
wrapped
- The resource handler to be wrapped.public static void addFacesServletMappingsIfNecessary(ServletContext servletContext) throws MalformedURLException
FacesServlet
to the URIs specified in "org.omnifaces.VIEW_RESOURCE_HANDLER_URIS"
context parameter.
This is invoked by ApplicationListener
, because the faces servlet registration has to be available for adding new mappings.servletContext
- The involved servlet context.MalformedURLException
- When one of the URIs specified in context parameter is malformed.public static boolean isViewResourceRequest(FacesContext context)
true
if the current HTTP request is requesting for a view resource managed by this resource handler.context
- The involved faces context.true
if the current HTTP request is requesting for a view resource managed by this resource handler.public ViewResource createViewResource(FacesContext context, String resourceName)
Faces.getRequestServletPath()
is returned as concrete resource rather than the provided resourceName
when the isViewResourceRequest(FacesContext)
returns true.createViewResource
in class ResourceHandlerWrapper
Copyright © 2012–2021 OmniFaces. All rights reserved.