开发者

primefaces update <head> content of a page

开发者 https://www.devze.com 2023-04-02 12:42 出处:网络
I have a page Create.xhtml that contains <p:calendar .... /> In another page List.xhtml, that NOT CONTAINS ANY <p:calendar/>,

I have a page Create.xhtml that contains

<p:calendar .... />

In another page List.xhtml, that NOT CONTAINS ANY <p:calendar/>,

with a Primefaces Ajax command (so WITHOUT ANY page recall/refresh) i call a

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

(Using the update param in the <p:ajax /> tag).

The included page is displayed, but the <p:calendar/> doesn't work because, the page <head> tag didn't load the Primefaces calendar library.

The only way to make <p:calendar/> work properly is to reload/refresh the entire page, but i need to do ajax request and update only the include, due to performance issues.

Is there any way to do it? Like refresh/update only the head tag?

EDIT: Create.xhtml content is in <ui:component> tag, and List.xhtml content is in a <ui:composition> tag (uses a template), both pages DON'T HAVE any <html&开发者_开发问答gt; , <head>/<h:head> or <body>/<h:body> tag. All these tags are in the template, used by List.xhtml


Thanks to Regis Machado that provided the solution i resolved the problem:

In my template, I just insert the <h:head> content in a div panel:

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

Then in List.xhtml:

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

In commandLink update, by putting :includePanel before :headPanel, the <head> tag is refreshed AFTER the page including, to let the browser renderer know what new script to import.

BTW: The second solution provided by Regis Machado works too, but isn't manageable, first of all because loanding scripts at startup (by inclunding a void calendar and fileupload) drastically reduces the application performance (thing reported in question), if more cases of pages including needed, and second makes code maintenance more complex.

Many thanks for the help, and hope can hel someone!


Try to use a ajax container component, i have the same issue with RichFaces 4, and put the <h:head> inside a <a4j:outputPanel>, and when i open a modal, i call the outputPanel id to render, then the resources are updated.. if i see in my post request has a <partial-response><changes><update id="pageHead"> .. this is not the best option but for now helped me.

my code:

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

< EDITED >
If this don't work, try tu put in your root template,if you have one, the components you need, but don't render it, this worked too, for me.

ex:

in my root template page i put

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

This force the jsf to identify and load the components resources, but don't render components.

< - > Sry for my english.

0

精彩评论

暂无评论...
验证码 换一张
取 消