3

PrimeFaces 有条件地在 h:head 中呈现以下内容:

<script type="text/javascript" src="/webapp/javax.faces.resource/push/push.js.jsf?ln=primefaces"><!--//--></script>

当 PrimeFaces p:socket 组件被添加到 JSF/xhtml 页面时。我的一些页面刷新,导致这个 push.js 文件“不”在 h:head 中呈现。

当 push.js 文件“未”呈现时,我想有条件地呈现 push.js 文件以尝试修复/解决我在 PrimeFaces Push 中遇到的问题。

更多详情请点击下方PrimeFaces论坛主题网址:

未捕获的类型错误:未定义不是函数

我在问这个问题,因为我已经根据 bean 属性值有条件地渲染 h:head,如下所示:

<h:head rendered="#{!pageNavigationController.gmaps and !pageNavigationController.gmapsAutoComplete}">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="refresh" content="#{session.maxInactiveInterval};url=pf_viewExpired.jsf" />
    <title><h:outputText escape="false" value="MCMS"/></title>
    <h:outputStylesheet name="css/mcms.css"/>
    <h:outputScript name="js/mcms.js"/>
    <h:outputScript name="js/addUsingTemplate.js"
                    rendered="#{pageNavigationController.isPageSelected('/orders/pf_AddUsingTemplate.xhtml')}"/>
</h:head>

也许我对 h:head 的使用使容器 TomEE 1.5 SNAPSHOT 难以为 .js 文件提供服务,因为页面上多个 h:head 的条件渲染,或者这实际上可能是 PrimeFaces Push (Atmosphere) 问题这最终需要解决,但我确信有一种方法可以通过 h:outputScript 渲染 .js 文件,如果该文件尚未在 h:head 中呈现的话。

Web 应用程序使用以下内容:

PrimeFaces 3.5 快照、TomEE 1.5 快照(Tomcat 7.0.32)、JUEL 2.2.5、OmniFaces 1.3 快照

请指教。

4

1 回答 1

4

这似乎更像是一个 PrimeFaces 问题。为了强制加载push.js同一视图上的每个请求,您可以显式添加

<h:outputScript library="primefaces" name="push/push.js" target="head" /> 

without conditional rendering. If everything went well, i.e. it behaves well as per JSF2 resource handling mechanism, then it should not be included twice at all in cases where it worked properly.

于 2012-11-23T17:16:43.310 回答