如果在全页刷新(FPR)之后未呈现文件,我该如何有条件地在h:head中呈现.js文件? [英] How can I conditionally render .js file in h:head, if file was not rendered after Full Page Refresh (FPR)?

查看:201
本文介绍了如果在全页刷新(FPR)之后未呈现文件,我该如何有条件地在h:head中呈现.js文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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论坛主题URL:

未捕获的TypeError:未定义不是函数

我问这个问题,因为我已经有条件地基于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的条件渲染,也许我对h:head的使用使TomTo 1.5 SNAPSHOT容器难以提供.js文件,或者实际上可能是PrimeFaces Push( Atmosphere)问题最终需要解决,但是我敢肯定,如果尚未在h:head中呈现该文件,则可以通过h:outputScript呈现该.js文件.

该Web应用程序正在使用以下内容:

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

请告知.

解决方案

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

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

没有条件渲染.如果一切顺利,即按照JSF2资源处理机制运行良好,则在正常工作的情况下,不应将其全部包含两次.

PrimeFaces conditionally renders the following in h:head:

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

when PrimeFaces p:socket component is added to JSF/xhtml page. Some of my page refreshes, result in this push.js file 'not' being rendered in h:head.

When push.js file is 'not' rendered, I would like to conditionally render the push.js file in attempt to fix/workaround an issue I'm having with PrimeFaces Push.

For more details, please click PrimeFaces forum topic URL below:

Uncaught TypeError: undefined is not a function

I am asking this question, because I am already conditionally rendering h:head based on bean attribute values, such as the following:

<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>

Maybe my use of h:head is making it difficult for the container TomEE 1.5 SNAPSHOT to serve the .js file, because of the conditional rendering of multiple h:head on the page, or this may actually be a PrimeFaces Push (Atmosphere) issue that ultimately needs to be solved, but I'm sure there is a way to render the .js file via h:outputScript, if the file is not rendered in h:head already.

The web application is using the following:

PrimeFaces 3.5 SNAPSHOT, TomEE 1.5 SNAPSHOT (Tomcat 7.0.32), JUEL 2.2.5, OmniFaces 1.3 SNAPSHOT

Please advise.

解决方案

This seems more like a PrimeFaces issue. In order to force loading of push.js on every request on the same view, you could explicitly add a

<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.

这篇关于如果在全页刷新(FPR)之后未呈现文件,我该如何有条件地在h:head中呈现.js文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆