Updating <p:resources /> with dyanmic content from AJAX

UI Components for JSF
Post Reply
gerryjun
Posts: 5
Joined: 06 Dec 2010, 13:39
Location: Philippines

06 Dec 2010, 13:49

Hi,

it seams <p:resources /> is dynamically loading the needed css and js as required, but im loading my main content via AJAX from a navigation.

This means that my headers remain static although the content changes from one page to another via AJAX.

When a page is loaded with primefaces component, the necessary <p:resources /> are not present.

Questions:

- how do i dynamically update the <p:resources /> ?
- Or how can i load everything on <p:resources />, so everything are available when needed?

using old primefaces 1.1 as updating legacy.


Thanks
Last edited by gerryjun on 07 Dec 2010, 04:18, edited 1 time in total.
Certified: SCJP & SCWCD
Java, Seam 2.1, Struts, Hibernate 3, JSF, Richfaces, Primefaces, Quartz, MySQL.

vanjadardic
Posts: 55
Joined: 08 Sep 2010, 09:18
Location: Banja Luka, Bosnia and Herzegovina
Contact:

06 Dec 2010, 14:51

I had the same problem. I solved it by adding dummy components on my template.

Code: Select all

<h:form id="dummy">
  <p:dataTable style="display: none;"/>
  <p:column style="display: none;"/>
  <p:commandLink style="display: none;"/>
  <p:commandButton style="display: none;"/>
  <p:dialog/>
  <p:fileUpload style="display: none;"/>
  <p:tabView rendered="false">
    <p:tab title=""/>
  </p:tabView>
  <p:message for="dummy"/>
  <f:ajax event="click"/>
</h:form>
So the resources for these components are always included in head secton.
PrimeFaces version: whatever is the latest
Mojarra version: whatever is the latest
GlassFish & Tomcat version: whatever is the latest
Chrome & Firefox version: whatever is the latest
And a little bit of IE

gerryjun
Posts: 5
Joined: 06 Dec 2010, 13:39
Location: Philippines

07 Dec 2010, 04:19

Hi vanjadardic,

Thanks for tip, it help solved my problem. Its not a efficient workaround, but it works.

Thanks
Certified: SCJP & SCWCD
Java, Seam 2.1, Struts, Hibernate 3, JSF, Richfaces, Primefaces, Quartz, MySQL.

vanjadardic
Posts: 55
Joined: 08 Sep 2010, 09:18
Location: Banja Luka, Bosnia and Herzegovina
Contact:

07 Dec 2010, 08:16

Yeah, I know, but what can you do :?:
PrimeFaces version: whatever is the latest
Mojarra version: whatever is the latest
GlassFish & Tomcat version: whatever is the latest
Chrome & Firefox version: whatever is the latest
And a little bit of IE

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

07 Dec 2010, 12:37

Hi,

If components are built programmatically and loaded per Ajax dynamically, you need an update of h:head component. Point to this component in the "update" (PF) / "render" (f:ajax) attribute. It should help you.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

gerryjun
Posts: 5
Joined: 06 Dec 2010, 13:39
Location: Philippines

07 Dec 2010, 12:46

I'll consider that if and when ever i get to use JSF 2.0, my current version does not seam to afford us that option to use h:head.

I might be wrong but it does not seem to be available in JSF 1.2.

Thanks
Certified: SCJP & SCWCD
Java, Seam 2.1, Struts, Hibernate 3, JSF, Richfaces, Primefaces, Quartz, MySQL.

vanjadardic
Posts: 55
Joined: 08 Sep 2010, 09:18
Location: Banja Luka, Bosnia and Herzegovina
Contact:

07 Dec 2010, 12:58

If components are built programmatically and loaded per Ajax dynamically, you need an update of h:head component. Point to this component in the "update" (PF) / "render" (f:ajax) attribute. It should help you.
I already tried that, but it didn't work. I was testing with Firefox, and when I refresh the h:head section, and right-click select 'View Page Source' the new head section is there, but Firefox doesn't actually load the new resources until full page refresh. :cry:
PrimeFaces version: whatever is the latest
Mojarra version: whatever is the latest
GlassFish & Tomcat version: whatever is the latest
Chrome & Firefox version: whatever is the latest
And a little bit of IE

gerryjun
Posts: 5
Joined: 06 Dec 2010, 13:39
Location: Philippines

07 Dec 2010, 14:28

Its probably due to browser caching :( , if indeed it was rerendered, it could be solved by appending random parameters to the resource if we had access to modify it or marking the resource as no-cache

ex. < src="/resource/file.js?342432342424">
Certified: SCJP & SCWCD
Java, Seam 2.1, Struts, Hibernate 3, JSF, Richfaces, Primefaces, Quartz, MySQL.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests