Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Unfortunately there is no generic solution here, yet. But instrumenting ResourceHandler you can implement this an official way (since JSF 2):</p> <pre><code>public class TestResourceHandler extends ResourceHandlerWrapper { public static final class TestResource extends Resource { @Override public InputStream getInputStream() throws IOException { return null; } @Override public Map&lt;String, String&gt; getResponseHeaders() { return new HashMap&lt;&gt;(); } @Override public String getRequestPath() { FacesContext context = FacesContext.getCurrentInstance(); return context.getApplication().getViewHandler().getResourceURL( context, "/faces" + RESOURCE_IDENTIFIER + "/test.gif?ln=test"); } @Override public URL getURL() { return null; } @Override public boolean userAgentNeedsUpdate(FacesContext context) { return true; } } private ResourceHandler wrapped; public TestResourceHandler(ResourceHandler wrapped) { this.wrapped = wrapped; } @Override public ResourceHandler getWrapped() { return wrapped; } @Override public Resource createResource(String resourceName, String libraryName) { if ("test".equals(libraryName)) return new TestResource(); return super.createResource(resourceName, libraryName); } @Override public boolean libraryExists(String libraryName) { if ("test".equals(libraryName)) return true; return super.libraryExists(libraryName); } @Override public void handleResourceRequest(FacesContext context) throws IOException { String library = context.getExternalContext().getRequestParameterMap().get("ln"); if ("test".equals(library)) { BufferedImage image = ImageIO.read(getClass().getResource("/info.png")); context.getExternalContext().setResponseContentType("image/gif"); ImageIO.write(image, "gif", context.getExternalContext().getResponseOutputStream()); context.responseComplete(); } else { wrapped.handleResourceRequest(context); } } } </code></pre> <p>And registered in the faces-config.xml:</p> <pre><code>&lt;faces-config&gt; &lt;application&gt; ... &lt;resource-handler&gt;com.intersult.test.util.TestResourceHandler&lt;/resource-handler&gt; &lt;/application&gt; ... &lt;/faces-config&gt; </code></pre> <p>Access the resource via /faces/javax.faces.resource/test.gif?ln=test or </p> <p>This solution works both in the application itself and in any JSF-library included in the base application WAR.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload