Exclude RichFaces JS files in CombinedResourceHandler

600 views Asked by At

Is it possible for the CombinedResourceHandler to ignore RichFaces JS files?

When I let omnifaces combine all JS files, including RichFaces with Richfaces optimisation off

<context-param>
   <param-name>org.richfaces.resourceOptimization.enabled</param-name>
   <param-value>false</param-value>
</context-param>

I get the following exception

SEVERE: Error Rendering View[/login.xhtml]
java.lang.UnsupportedOperationException
    at org.richfaces.resource.ExternalStaticResource.getURL(ExternalStaticResource.java:90)
    at org.omnifaces.resourcehandler.CombinedResourceInfo.loadResources(CombinedResourceInfo.java:229)
    at org.omnifaces.resourcehandler.CombinedResourceInfo.getLastModified(CombinedResourceInfo.java:303)
    at org.omnifaces.resourcehandler.CombinedResource.getRequestPath(CombinedResource.java:92)
    at com.sun.faces.renderkit.html_basic.StylesheetRenderer.encodeEnd(StylesheetRenderer.java:106)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
    at com.sun.faces.renderkit.html_basic.HeadRenderer.encodeHeadResources(HeadRenderer.java:105)
    at com.sun.faces.renderkit.html_basic.HeadRenderer.encodeEnd(HeadRenderer.java:92)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.caucho.server.webbeans.ConversationJsfViewHandler.renderView(ConversationJsfViewHandler.java:81)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.render(CodiLifecycleWrapper.java:126)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    ...

However, regardless of what I enter in the context param org.omnifaces.COMBINED_RESOURCE_HANDLER_EXCLUDED_RESOURCES, I am unable to exclude any of the Richfaces resources. I tried param values such as

<param-value>richfaces:richfaces.js, richfaces:richfaces-queue.js, richfaces:richfaces-base-component.js</param-value>
1

There are 1 answers

6
BalusC On BEST ANSWER

You need to supply the exact resource identifiers. Those aren't valid RichFaces resource identifiers. You seem to have guessed them. You can easily determine them by looking at the generated HTML output when not using CombinedResourceHandler. Given a context path of /playground and JSF mapping of *.xhtml, it'll look something like this:

<script type="text/javascript" src="/playground/javax.faces.resource/richfaces.js.xhtml"></script>
<script type="text/javascript" src="/playground/javax.faces.resource/richfaces-base-component.js.xhtml"></script>

The part after the /javax.faces.resource/ without JSF mapping is the resource name. The part in the ln request parameter is the resource library (however, as you probably observed, RichFaces has none!). The resource identifier is represented by library:name notation, or just name if there's no library.

So, this should do it for you:

<context-param>
    <param-name>org.omnifaces.COMBINED_RESOURCE_HANDLER_EXCLUDED_RESOURCES</param-name>
    <param-value>richfaces.js, richfaces-queue.js, richfaces-base-component.js</param-value>
</context-param>

Note that disobeying the resource library (and homebrewing another layer over it) is indeed a severe mistake of RichFaces. See also among others What is the JSF resource library for and how should it be used?


Unrelated to the concrete question, I can't reproduce issue 39 anymore using RichFaces 4.3.6. Feel free to reopen the issue at GitHub, along with the minimum information necessary to reproduce the problem ourselves starting with a completely blank project.