我想一次使用OmniFaces CombinedResourceHandler来流资源。
我在faces-config.xml中注册了它,没有任何其他配置参数,如CombinedResourceHandler文档中所描述的。
虽然它可以很好地处理CSS资源,但是它对JavaScript资源不做任何事情。以下是我的测试:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com /jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:o="http://omnifaces.org/ui">
<h:head>
<title>CombinedResourceHandlerTest</title>
<h:outputStylesheet name="css/bootstrap-3.3.5/bootstrap.css"/>
<h:outputStylesheet name="css/main.css" />
<h:outputScript name="js/jquery/jquery.min.js"/>
<h:outputScript name="js/bootstrap-3.3.5/bootstrap.min.js"/>
</h:head>
<h:body>
<f:view>
<h2>CombinedResourceHandlerTest</h2>
</f:view>
</h:body> 输出:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>CombinedResourceHandlerTest</title>
<script type="text/javascript" src="/testApp/javax.faces.resource/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/testApp/javax.faces.resource/js/bootstrap-3.3.5/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="/testApp/javax.faces.resource/eNpLLi7WT8rPLykuKUos0DXWM9YzRfD1kouLa4BYPzcxMw_EAQCLpxEP.css?ln=omnifaces.combined&v=1480321351184">
</head>尝试了属性target="head":
<h:head>
<h:outputScript name="js/jquery/jquery.min.js" target="head"/>
</h:head>
...
输出:(脚本完全丢失):
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>CombinedResourceHandlerTest</title>
<link type="text/css" rel="stylesheet" href="/testApp/javax.faces.resource/eNpLLi7WT8rPLykuKUos0DXWM9YzRfD1kouLa4BYPzcxMw_EAQCLpxEP.css?ln=omnifaces.combined&v=1480321351184">
</head>
...
</html>当我将脚本移到身体顶部时,脚本也会丢失:
<h:body>
<h:outputScript name="js/jquery/jquery.min.js" target="head"/>
....
</h:body> 在查看了一下我也尝试过的来源之后
<o:deferredScript name="js/jquery/jquery.min.js"/>在检查了本例的输出后,我看到组合脚本只按顺序包含第一个脚本,控制台显示"ReferenceError: OmniFaces未定义“:
<body>
<script type="text/javascript">OmniFaces.DeferredScript.add('/testApp/javax.faces.resource/eNpLL81JLE7OsMoq1s8qLE0tqoRSermZeXpZxQDDagwa.js?ln=omnifaces.combined&v=0');</script>
</body>我注意到,即使是jsf.js也不包括在使用CombinedResourceHandler活动时。浏览器控制台告知“未定义mojarra”。
我做错了什么?提前感谢!
我的环境是: Mojarra 2.2.12,OmniFaces2.5.1,Tomcat 8。
发布于 2016-12-19 11:50:19
上周末,我复制了一个非常相似的问题。原因归结为Mojarra在Tomcat 8服务器上被初始化了两次,因此损坏了一个服务器和另一个服务器。您可以通过查看服务器日志来确认这一点,并注意到,除其他外,Mojarra版本、OmniFaces版本和PrimeFaces版本被记录了两次。
如果您只有一个Mojarra实例,并且您做的是而不是,请双验证在web.xml中使用ConfigureListener条目,如下所示,因为默认情况下它已经自动注册了。
<!-- You MUST remove this one from web.xml! -->
<!-- This is actually a workaround for buggy GlassFish3 and Jetty servers. -->
<!-- When leaving this in and you're targeting Tomcat, you'll run into trouble. -->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>另请参阅:
发布于 2019-03-11 12:47:04
对于其他遇到这个问题的人,我也使用JBossEAP7.1遇到了这个问题。
我意外地在Web片段JAR中的Facs-config.xml和web应用程序本身的Facs-config.xml中声明了OmniFacesCombinedResourceHandler。两次声明导致了与上述问题相同的症状。一旦我从webapp faces-config.xml中删除了它,它就开始工作了。
我在OmniFaces问题上提出了问题,如果发生这种情况,可能会检测并引发错误:https://github.com/omnifaces/omnifaces/issues/504
https://stackoverflow.com/questions/40948684
复制相似问题