Exclude RichFaces JS files in CombinedResourceHandler

允我心安 提交于 2021-01-29 04:23:47

问题


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:


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.



来源:https://stackoverflow.com/questions/23824219/exclude-richfaces-js-files-in-combinedresourcehandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!