Package org.omnifaces.resourcehandler
Class VersionedResourceHandler
- java.lang.Object
-
- jakarta.faces.application.ResourceHandler
-
- jakarta.faces.application.ResourceHandlerWrapper
-
- org.omnifaces.resourcehandler.DefaultResourceHandler
-
- org.omnifaces.resourcehandler.VersionedResourceHandler
-
- All Implemented Interfaces:
FacesWrapper<ResourceHandler>
public class VersionedResourceHandler extends DefaultResourceHandler
Automatically adds version parameter with query string namev
to all resource URLs so, in production mode they will be cached forever (or as configured in web.xml), but will not be stale when a new version of the app is deployed.NOTE: if resource URL already has
v
query string parameter, or when it is URL-rewritten to not include"/jakarta.faces.resource"
path anymore, then these will be ignored.Example:
faces-config.xml:
<application> <resource-handler>org.omnifaces.resourcehandler.VersionedResourceHandler</resource-handler> </application>
web.xml:<context-param> <!-- Mojarra: 1 year cache, effects production mode only --> <param-name>com.sun.faces.defaultResourceMaxAge</param-name> <param-value>31536000000</param-value> </context-param> <context-param> <param-name>org.omnifaces.VERSIONED_RESOURCE_HANDLER_VERSION</param-name> <!-- Version string could be any string here, or taken from @Named bean --> <param-value>#{environmentInfo.version}</param-value> </context-param>
- Since:
- 3.9
- Author:
- Lenny Primak
-
-
Field Summary
Fields Modifier and Type Field Description static String
PARAM_NAME_VERSION
The context parameter name to specify value of the version to be appended to the resource URL.-
Fields inherited from class org.omnifaces.resourcehandler.DefaultResourceHandler
FACES_SCRIPT_RESOURCE_NAME, RES_NOT_FOUND
-
Fields inherited from class jakarta.faces.application.ResourceHandler
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 Summary
Constructors Constructor Description VersionedResourceHandler(ResourceHandler wrapped)
Creates a new instance of this versioned resource handler which wraps the given resource handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource
decorateResource(Resource resource)
Decorate the given resource.-
Methods inherited from class org.omnifaces.resourcehandler.DefaultResourceHandler
createResource, createResource, createResource, createResourceFromLibrary, decorateResource, getLibraryName
-
Methods inherited from class jakarta.faces.application.ResourceHandlerWrapper
createResourceFromId, createViewResource, getRendererTypeForResourceName, getViewResources, getViewResources, getWrapped, handleResourceRequest, isResourceRendered, isResourceRequest, isResourceURL, libraryExists, markResourceRendered
-
-
-
-
Field Detail
-
PARAM_NAME_VERSION
public static final String PARAM_NAME_VERSION
The context parameter name to specify value of the version to be appended to the resource URL.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VersionedResourceHandler
public VersionedResourceHandler(ResourceHandler wrapped)
Creates a new instance of this versioned resource handler which wraps the given resource handler. This will also initialize the version based on the context parameter.- Parameters:
wrapped
- The resource handler to be wrapped.
-
-
Method Detail
-
decorateResource
public Resource decorateResource(Resource resource)
Description copied from class:DefaultResourceHandler
Decorate the given resource. This will only be called if no library-specific resource has been requested.The default implementation just returns the given resource unmodified.
- Overrides:
decorateResource
in classDefaultResourceHandler
- Parameters:
resource
- The resource to be decorated.- Returns:
- The decorated resource.
-
-