• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Performance issues using ajax

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I am new to Java EE.
I am using JPA+EJB+JSF+PrimeFaces in my project.
I am writing everything using ajax. I already wrote a lot, but I encounter some performance issues. After investigation I found that every time ajax is fired from client - all EL expressions in my whole page are executed. Which is weird because I specify process/execute and update/render attributes correctly, and I never update @all ...
That behavior is present in the JSF, as in JSF+PrimeFaces.
1. Is it normal ?
2. How can I optimize, so it won't execute all page every time.
Thanks in advance.

UPDATE:
I stand corrected - not all EL expressions are executed in my page. Only those which are in <c:ForEach> <ui:repeat>. They are executed even when I specify update/render to @none in <f:ajax> tag...
Can anyone tell me how can I change this behavior ?
 
Saloon Keeper
Posts: 28720
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Pry!

First, get rid of the JSTL. JSTL does not work well in JSF. JSF has equivalent constructs that make JSTL mostly unnecessary. The cases where JSF can't do what JSTL can do are almost always cases where people are trying to pollute their View definitions with Controller code - JSF is very much a MVC framework. JSTL is not.
 
Zachary Pry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply.
I never used c:forEach, I am using ui:repeat everywhere.
But in PrimeFaces I need to create tabs using c:forEach: (Quote from documentation) "Use c:forEach to create tabs on the fly, ui:repeat will not work as p:tab has no Renderer.". So I am using forEach in my code only in that case.
When I will get to my home computer - I will write small template project which will demonstrate problem and post it here. This problem is easier to show than explain.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I didn't worked with the PrimeFaces, my answear is based on richfaces and icefaces I've used.
1. What you've described is a normal behaviour. If you place an event listener on a component, the whole form is sent and the whole jsf ui tree is generated even you rerender only a designated node.
2. What can you do is to specify to update only a single bean attribute, but I don't know exact syntax for PF :-( in RF it's an attribute for the ajax support element.
Regards
G.
 
Zachary Pry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply.
I've already wrote simple code (in pure JSF) to demonstrate the problem I am having:

index.xhtml


MainManager.java


Even when I fire ajax event (via commandButton) to execute and render @form only - getNames() still executes.
But it looks like that Gabriel Vince already answered my question - if JSF builds whole UI Tree before render then it must execute all ui:repeat and c:forEach tags... So I guess that the only solution for this case is PartialViewContext...
Thanks to all for your attention to this topic... and answers of course

UPDATE: Solution for those who might need it:
use FacesContext.getCurrentInstance().getPartialViewContext().isAjaxRequest() in conjunction with FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().
Unfortunately I knew about this solution, but in my case - it creates some amount of complications which I need to overcome. And I thought that there is a better way to solve this...
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Zachary,

Your other option may be to make some of the JSF stuff stateless to avoid rendering of the page. This is not native to the JSF implementation but we have had a crack at it to assist with similar issues when dealing with a JSF / Client Side Javascript AJAX type situation you are describing.

There is a better explanation and sample implementation here:
http://industrieit.com/blog/2011/11/stateless-jsf-high-performance-zero-per-request-memory-overhead/

Cheers
Brendan
 
Zachary Pry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brendan. Thank you for your reply.

I've fixed it by completely rewriting that piece . Right now this part of the page is generated dynamically in a request scoped Managed Beans.

I'll definitively read that article. It is very interesting.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic