Primefaces更新<head>页面的内容

primefaces update <head> content of a page

本文关键字:head 更新 Primefaces      更新时间:2023-09-26

我有一个包含

的页面Create.xhtml
<p:calendar .... />

在另一个页面List.xhtml中,不包含任何<p:calendar/>

与Primefaces Ajax命令(所以没有任何页面召回/刷新),我调用

<ui:include src="Create.xhtml"/>

(使用<p:ajax />标签中的update参数)。

显示包含的页面,但<p:calendar/>不工作,因为,<head>页面标签没有加载Primefaces日历库。

使<p:calendar/>正常工作的唯一方法是重新加载/刷新整个页面,但我需要做ajax请求和更新仅包括,由于性能问题。

有办法吗?比如只刷新/更新头部标签?

编辑:Create.xhtml内容在<ui:component>标签中,List.xhtml内容在<ui:composition>标签中(使用模板),两个页面都没有任何<html>, <head>/<h:head><body>/<h:body>标签。所有这些标记都在模板中,由List.xhtml

使用

感谢Regis Machado提供的解决方案,我解决了这个问题:

在我的模板中,我只是在div面板中插入<h:head>内容:
<!-- by layout="block" the panelGroup is rendered as a div, omitting as span -->
<h:panelGroup id="headPanel" layout="block">
   <h:head>
        <!-- Head Content -->
   </h:head>
</h:panelGroup>

然后在List.xhtml中:

<p:commandLink value="Create" actionListener="#{myBean.toggleInclude}" update=":includePanel,:headPanel"/>

在commandLink update中,通过将:includePanel放在:headPanel之前,<head>标签在页面包含之后刷新,以让浏览器渲染器知道要导入的新脚本。

顺便说一句:Regis Machado提供的第二个解决方案也有效,但不易于管理,首先是因为在启动时加载脚本(通过包含一个无效的日历和文件上传)会大大降低应用程序的性能(报告中的问题),如果需要更多的页面,第二使代码维护更加复杂。

非常感谢你的帮助,希望能帮助别人!

尝试使用ajax容器组件,我有与RichFaces 4相同的问题,并将<h:head>放在<a4j:outputPanel>内,当我打开一个模态时,我调用outputPanel id来渲染,然后资源更新。如果我看到我的帖子请求有<partial-response><changes><update id="pageHead"> ..这不是最好的选择,但现在对我有帮助。

我的代码:

<a4j:outputPanel id="pageHead"> <h:head> <title>Portal - <ui:insert name="title" /></title> <ui:include src="../../resources-portal/includes/portal/head.xhtml"/> <ui:insert name="head"/> </h:head> </a4j:outputPanel>

& lt;编辑>
如果这不起作用,试着把你需要的组件放在你的根模板中,如果你有一个,但不要渲染它,这对我来说也是有效的。

,

在我的根模板页面,我把

  <rich:calendar rendered="false"/>
  <rich:fileUpload rendered="false"/>

这将强制jsf识别并加载组件资源,但不呈现组件。

& lt;->对不起我的英语。