aspose file tools*
The moose likes JSF and the fly likes Performance issues using ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Performance issues using ajax" Watch "Performance issues using ajax" New topic

Performance issues using ajax

Zachary Pry

Joined: Aug 09, 2011
Posts: 18
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.

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 ?

Open-source JDBC Library - Midao JDBC ( ).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137

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.

Customer surveys are for companies who didn't pay proper attention to begin with.
Zachary Pry

Joined: Aug 09, 2011
Posts: 18
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.
Gabriel Vince

Joined: Feb 05, 2009
Posts: 24
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.
Zachary Pry

Joined: Aug 09, 2011
Posts: 18
Thank you for your reply.
I've already wrote simple code (in pure JSF) to demonstrate the problem I am having:


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...
Brendan Haire

Joined: Nov 24, 2011
Posts: 1
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:

Zachary Pry

Joined: Aug 09, 2011
Posts: 18
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.
I agree. Here's the link:
subject: Performance issues using ajax