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