ResourceHandler is the
run-time API by which jakarta.faces.component.UIComponent and jakarta.faces.render.Renderer
instances, and the jakarta.faces.view.ViewDeclarationLanguage can reference
Resource instances. An implementation of this class must be thread-safe.
Packaging Resources
ResourceHandler defines a path based packaging convention for resources. The default implementation of
ResourceHandlermust support packaging resources in the classpath or in the web application root. See section 2.6.1 "Packaging Resources" of the Jakarta Faces Specification Document for the normative specification of packaging resources.Briefly, The default implementation must support packaging resources in the web application root under the path
resources/<resourceIdentifier>relative to the web app root. "resources" is the default location, but this location can be changed by the value of the
WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME<context-param>.For the default implementation, resources packaged in the classpath must reside under the JAR entry name
META-INF/resources/<resourceIdentifier>In the case of Faces Flows packaged within jar files, resources packaged in the classpath must reside under the jar entry name
META-INF/flows/<resourceIdentifier>
<resourceIdentifier>consists of several segments, specified as follows.
[localePrefix/][libraryName/][libraryVersion/]resourceName[/resourceVersion]None of the segments in the resourceIdentifier may be relative paths, such as ‘../otherLibraryName’. The implementation is not required to support the
libraryVersionandresourceVersionsegments for the JAR packaging case.Note that resourceName is the only required segment.
Encoding Resources
During the handling of view requests, the Jakarta Server Face run-time may be called upon to encode a resource in such a way as to instruct the user-agent to make a subsequent resource request. This behavior is orchestrated by one of the resource renderers (
ScriptRenderer,StylesheetRenderer,ImageRenderer), which all callResource#getRequestPathto obtain the encoded URI for the resource. SeeResource#getRequestPathand the Standard HTML RenderKit specification for the complete specification.This usage of resources does not apply for resources that correspond to VDL resources.
Decoding Resources
During the handling of resource requests, the Jakarta Faces run-time will be called upon to decode a resource in such a way as to serve up the bytes of the resource to the user-agent. This behavior is orchestrated by
handleResourceRequest, which callsResource#getInputStreamto obtain bytes of the resource. SeehandleResourceRequestfor the complete specification.This usage of resources does not apply for resources that correspond to VDL resources.
| Modifier and Type | Field and Description |
|---|---|
| public static final String | FACES_SCRIPT_LIBRARY_NAME
Library name of Jakarta Faces script resource. |
| public static final String | FACES_SCRIPT_RESOURCE_NAME
Resource name of Jakarta Faces script resource. |
| public static final String | JSF_SCRIPT_LIBRARY_NAME
Library name of Jakarta Faces script resource. |
| public static final String | JSF_SCRIPT_RESOURCE_NAME
Resource name of Jakarta Faces script resource. |
| public static final String | LOCALE_PREFIX
The name of a key within the application message bundle named by the return from |
| public static final String | RESOURCE_CONTRACT_XML
This file must be located in |
| public static final String | RESOURCE_EXCLUDES_DEFAULT_VALUE
The default value for the |
| public static final String | RESOURCE_EXCLUDES_PARAM_NAME
The |
| public static final String | RESOURCE_IDENTIFIER
|
| public static final String | WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME
If a |
| public static final String | WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME
If a |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract Resource | Returns: a newly createdResource instance, suitable for use in encoding or decoding the named resource.the name of the resource. resourceName)
Create an instance of |
| public abstract Resource | Returns: a newly createdResource instance, suitable for use in encoding or decoding the named resource.the name of the resource. resourceName, String the name of the library (or contract) in which this
resource resides, may be libraryOrContractName)null. If there is a conflict between the name of a resource library and a
resource library contract, the resource library takes precedence. May not
include relative paths, such as "../".
Create an instance of |
| public abstract Resource | Returns: a newly createdResource instance, suitable for use in encoding or decoding the named resource.the name of the resource. resourceName, String the name of the library in which this resource resides, may be libraryName, String null.
May not include relative paths, such as "../".the mime content that this contentType)Resource instance will return from
Resource#getContentType. If the value is null, The content-type of the resource is derived by
passing the resourceName to jakarta.faces.context.ExternalContext#getMimeType
Create an instance of |
| public Resource | Returns: a newly createdResource instance, suitable for use in encoding or decoding the named resource.the resource identifier of the resource. resourceId)
Create an instance of |
| public ViewResource | Returns: a newly createdViewResource instance, suitable for use by the
jakarta.faces.view.ViewDeclarationLanguage.the context, String FacesContext for this request.the name of the resource to be interpreted as a view by the
resourceName)jakarta.faces.view.ViewDeclarationLanguage.
Create an instance of |
| public abstract String | Returns: the renderer type.the resource name. resourceName)
Return the |
| public Stream | Returns: theStream of view resource namesThe facesContext, String FacesContext for this request.The initial path from which to start looking for view resources path, int The absolute maximum depth of nested directories to visit counted from the root ( maxDepth, ResourceVisitOption... /).The options to influence the traversal. See options)ResourceVisitOption for details on those.
Return a |
| public Stream | Returns: theStream of view resource namesThe facesContext, String FacesContext for this request.The initial path from which to start looking for view resources path, ResourceVisitOption... The options to influence the traversal. See options)ResourceVisitOption for details on those.
Return a |
| public abstract void | handleResourceRequest(FacesContext
the context)jakarta.faces.context.FacesContext for this requestThis method specifies the contract for satisfying resource requests. |
| public boolean | Returns: Whether the resource as identified by given resource and library name has been rendered.The context, String FacesContext for this request.The name of the resource. resourceName, String The name of the library in which this resource resides, may be libraryName)null.Returns whether the resource as identified by given resource and library name has been rendered. |
| public abstract boolean | Returns: true if the current request is a resource request, false otherwise.the context)jakarta.faces.context.FacesContext for this request
Return |
| public boolean | Returns: true if this is a resource URL, false otherwise.the url to inspect for the presence of url)ResourceHandler#RESOURCE_IDENTIFIER.
Return |
| public abstract boolean | Returns: true if the library exists, false otherwise.the library name. libraryName)
Return |
| public void | markResourceRendered(FacesContext
The context, String FacesContext for this request.The name of the resource. resourceName, String The name of the library in which the resource resides, may be libraryName)null.Mark the resource as identified by given resource and library name as rendered. |
| FACES_SCRIPT_LIBRARY_NAME | back to summary |
|---|---|
| public static final String FACES_SCRIPT_LIBRARY_NAME Library name of Jakarta Faces script resource.
| |
| FACES_SCRIPT_RESOURCE_NAME | back to summary |
|---|---|
| public static final String FACES_SCRIPT_RESOURCE_NAME Resource name of Jakarta Faces script resource.
| |
| JSF_SCRIPT_LIBRARY_NAME | back to summary |
|---|---|
| public static final String JSF_SCRIPT_LIBRARY_NAME
Library name of Jakarta Faces script resource.
| |
| JSF_SCRIPT_RESOURCE_NAME | back to summary |
|---|---|
| public static final String JSF_SCRIPT_RESOURCE_NAME
Resource name of Jakarta Faces script resource.
| |
| LOCALE_PREFIX | back to summary |
|---|---|
| public static final String LOCALE_PREFIX
The name of a key within the application message bundle named by the return from | |
| RESOURCE_CONTRACT_XML | back to summary |
|---|---|
| public static final String RESOURCE_CONTRACT_XML
This file must be located in
| |
| RESOURCE_EXCLUDES_DEFAULT_VALUE | back to summary |
|---|---|
| public static final String RESOURCE_EXCLUDES_DEFAULT_VALUE
The default value for the | |
| RESOURCE_EXCLUDES_PARAM_NAME | back to summary |
|---|---|
| public static final String RESOURCE_EXCLUDES_PARAM_NAME
The | |
| RESOURCE_IDENTIFIER | back to summary |
|---|---|
| public static final String RESOURCE_IDENTIFIER
| |
| WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME | back to summary |
|---|---|
| public static final String WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME
If a
| |
| WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME | back to summary |
|---|---|
| public static final String WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME
If a
| |
| ResourceHandler | back to summary |
|---|---|
| public ResourceHandler() | |
| createResource | back to summary |
|---|---|
| public abstract Resource createResource(String resourceName)
Create an instance of
The algorithm specified in section 2.6.1.4 "Libraries of Localized and Versioned Resources" of the Jakarta Faces Specification Document
must be executed to create
the
| |
| createResource | back to summary |
|---|---|
| public abstract Resource createResource(String resourceName, String libraryOrContractName)
Create an instance of
The algorithm specified in section 2.6.1.4 "Libraries of Localized and Versioned Resources" of the Jakarta Faces Specification Document
must be executed to create
the
| |
| createResource | back to summary |
|---|---|
| public abstract Resource createResource(String resourceName, String libraryName, String contentType)
Create an instance of
The algorithm specified in section 2.6.1.4 "Libraries of Localized and Versioned Resources" of the Jakarta Faces Specification Document
must be executed to create
the
| |
| createResourceFromId | back to summary |
|---|---|
| public Resource createResourceFromId(String resourceId)
Create an instance of The resource must be identified according to the specification in section 2.6.1.3 "Resource Identifiers" of the Jakarta Faces Specification Document. New requirements were introduced in version 2.2 of the specification.
| |
| createViewResource | back to summary |
|---|---|
| public ViewResource createViewResource(FacesContext context, String resourceName)
Create an instance of The default implementation must look for the resource in the following places, in this order.
Call
| |
| getRendererTypeForResourceName | back to summary | ||||||
|---|---|---|---|---|---|---|---|
| public abstract String getRendererTypeForResourceName(String resourceName)
Return the
| |||||||
| getViewResources | back to summary |
|---|---|
| public Stream
Return a
The
| |
| getViewResources | back to summary |
|---|---|
| public Stream
Return a This method works as if invoking it were equivalent to evaluating the expression: Put differently, it visits all levels of the resource tree.getViewResources(facesContext, start, Integer.MAX_VALUE, options)
| |
| handleResourceRequest | back to summary |
|---|---|
| public abstract void handleResourceRequest(FacesContext context) throws IOException
This method specifies the contract for satisfying resource requests. This method is called from
The default implementation must implement an algorithm semantically identical to the following algorithm. For discussion, in all cases when a status code is to be set, this spec talks only using the Jakarta Servlet API, but it is understood that in a portlet environment the appropriate equivalent API must be used.
| |
| isResourceRendered | back to summary |
|---|---|
| public boolean isResourceRendered(FacesContext context, String resourceName, String libraryName)
Returns whether the resource as identified by given resource and library name has been rendered. The default
implementation must during the render response phase of the current view return
| |
| isResourceRequest | back to summary |
|---|---|
| public abstract boolean isResourceRequest(FacesContext context)
Return
| |
| isResourceURL | back to summary |
|---|---|
| public boolean isResourceURL(String url)
Return
| |
| libraryExists | back to summary |
|---|---|
| public abstract boolean libraryExists(String libraryName)
Return
| |
| markResourceRendered | back to summary |
|---|---|
| public void markResourceRendered(FacesContext context, String resourceName, String libraryName)
Mark the resource as identified by given resource and library name as rendered. The default implementation must
ensure that
| |