public class WebAppManifestResourceHandler extends DefaultResourceHandler
This ResourceHandler
generates the manifest.json
based on any WebAppManifest
found in the
runtime classpath.
WebAppManifest
in your web application project.ApplicationScoped
, SessionScoped
or even
RequestScoped
(note that a ViewScoped
obviously won't work).Here's a concrete example:
package com.example; import java.util.Arrays; import java.util.Collection; import javax.enterprise.context.ApplicationScoped; import org.omnifaces.resourcehandler.WebAppManifest; @ApplicationScoped public class ExampleWebAppManifest extends WebAppManifest { @Override public String getName() { return "Example Application Name"; } @Override public String getShortName() { return "EAN"; } @Override public Collection<ImageResource> getIcons() { return Arrays.asList( ImageResource.of("logo.svg"), ImageResource.of("logo-120x120.png", Size.SIZE_120), ImageResource.of("logo-180x180.png", Size.SIZE_180), ImageResource.of("logo-192x192.png", Size.SIZE_192), ImageResource.of("logo-512x512.png", Size.SIZE_512) ); } @Override public String getThemeColor() { return "#cc9900"; } @Override public String getBackgroundColor() { return "#ffffff"; } @Override public Display getDisplay() { return Display.STANDALONE; } @Override public Collection<Category> getCategories() { return Arrays.asList(Category.BUSINESS, Category.FINANCE); } @Override public Collection<RelatedApplication> getRelatedApplications() { return Arrays.asList( RelatedApplication.of(Platform.PLAY, "https://play.google.com/store/apps/details?id=com.example.app1", "com.example.app1"), RelatedApplication.of(Platform.ITUNES, "https://itunes.apple.com/app/example-app1/id123456789") ); } }
Finally reference it in your template exactly as follows, with the exact library name of omnifaces
and
exact resource name of manifest.json
. You cannot change these values.
<link rel="manifest" href="#{resource['omnifaces:manifest.json']}" crossorigin="use-credentials" />
The crossorigin
attribute is optional, you can drop it, but it's mandatory if you've put the
SessionScoped
annotation on your WebAppManifest
bean, else the browser won't retain the session
cookies while downloading the manifest.json
and then this resource handler won't be able to maintain the
cachability. See next section.
Basically, the CDI scope annotation being used is determinative for the autogenerated v=
query
parameter indicating the last modified timestamp. If you make your WebAppManifest
bean RequestScoped
,
then it'll change on every request and the browser will be forced to re-download it. If you can however guarantee
that the properties of your WebAppManifest
are static, and thus you can safely make it
ApplicationScoped
, then the v=
query parameter will basically represent the timestamp of
the first time the bean is instantiated.
Modifier and Type | Field and Description |
---|---|
static String |
RESOURCE_NAME |
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 |
---|
WebAppManifestResourceHandler(ResourceHandler wrapped)
Creates a new instance of this web app manifest resource handler which wraps the given resource handler.
|
Modifier and Type | Method and Description |
---|---|
Resource |
decorateResource(Resource resource,
String resourceName,
String libraryName)
Decorate the given resource.
|
createResource, createResource, createResource, createResourceFromLibrary, decorateResource, getLibraryName
createResourceFromId, createViewResource, getRendererTypeForResourceName, getViewResources, getViewResources, getWrapped, handleResourceRequest, isResourceRendered, isResourceRequest, isResourceURL, libraryExists, markResourceRendered
public static final String RESOURCE_NAME
public WebAppManifestResourceHandler(ResourceHandler wrapped)
WebAppManifest
.wrapped
- The resource handler to be wrapped.public Resource decorateResource(Resource resource, String resourceName, String libraryName)
DefaultResourceHandler
The default implementation delegates to DefaultResourceHandler.decorateResource(Resource)
.
decorateResource
in class DefaultResourceHandler
resource
- The resource to be decorated.resourceName
- The resource name.libraryName
- The library name.Copyright © 2012–2020 OmniFaces. All rights reserved.