我想一次使用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"/>
检查了此情况的输出后,我看到Comminend脚本仅包含第一个脚本,并且控制台显示" ReferenceError:omnifaces未定义":
<body>
<script type="text/javascript">OmniFaces.DeferredScript.add('/testApp/javax.faces.resource/eNpLL81JLE7OsMoq1s8qLE0tqoRSermZeXpZxQDDagwa.js?ln=omnifaces.combined&v=0');</script>
</body>
我注意到,当CombinedResourceHandler
处于Active时,即使不包括jsf.js
。浏览器控制台告诉"未定义的Mojarra"。
我在做什么错?预先感谢!
我的环境是:Mojarra 2.2.12,Omnifaces 2.5.1,Tomcat 8。
我上周末再现了一个非常相似的问题。原因归结为莫哈拉(Mojarra)在Tomcat 8服务器上两次初始化,因此损坏了该服务器。您可以通过查看服务器日志来确认这一点,并注意到Mojarra版本,Omnifaces版本和PrimeFaces版本已记录两次。
如果您只有一个mojarra实例,请双重ververify,并且您在 web.xml
中具有ConfigureListener
条目,如下所示,因为默认情况下已经autororegistered。
<!-- 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>
另请参见:
- com.sun.faces.config.configurelistener的配置
- 如何通过Maven正确安装和配置JSF库?
对于任何遇到此问题的人,我也使用JBOSS EAP 7.1遇到了这个问题。
我偶然地让omnifacesCombinedResourceHandler在faces-config.xml中声明了Web片段jar和Web应用程序本身的faces-config.xml。宣布这两次引起与上面列出的问题相同的症状。一旦我从webapp faces-config.xml删除它,就开始工作。
我提出了有关omnifaces问题的问题,如果发生这种情况,可能会检测并提出错误: