Skip to main content

serious performance bug with JSF2

7 replies [Last post]
leandro_komosinski
Offline
Joined: 2007-08-12

Hi,

Considering code below:

</p>
<p>

how many times the method getValues (from #{myBean.values}) should be called?

Answer:

* if you are using JSF 1.2 (Mojarra's 2.0.2 implementation): zero times. That is correct as panelGroup "p" is not rendered.

* if you are using JSF2 (Mojarra's 2.0.2 implementation): 10 times. That is incredible wrong!

Can anyone plase explain what's happening?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
healeyb
Offline
Joined: 2010-01-26

You're not the first person to notice this - I'm sure it's not necessary. The key
point is to ensure that you don't do database lookups in the getter for the
property used in the datatable value=. In fact it should just be a standard
ide generated getter really. Whenever you change the underlying data the
property should be reloaded, then the getter can return the updated data
from memory.

I have made the point that it's far from obvious that it works like this. When I
first experimenting with h:dataTable I looked at the value=, and though ok
I'll write a getter that retrieves the data from the database. It was only during
a debug session that I figured out what was going on and had to restructure
my code.

One thing you could try is using the primeFaces p:dataTable, I've not actually
checked to see if it's any better in this respect than h:dataTable, but it's a far
better componet in other respects.

Regards,
Brendan.

leandro_komosinski
Offline
Joined: 2007-08-12

Hi Brendan,

Actually I noticed the problem when I was using primeFaces. PrimeFace guys told me the problem is with JSF core.

There are two problems with JSF2 (Mojarra 2.0,2):

1) performance (the problem doesn't exist in JSF1.2)
2) bug (error) as component's methods should not be called at all if component is nested in a non rendered component. Again, JSF1.2 respects this.

If JSF is all about "component based development" (as it replaces JSP "page based development") then it doesn't make any sense "... to restructure my code". I understand you have done that as workaround solution.

Regards,

Leandro

leandro_komosinski
Offline
Joined: 2007-08-12

Just to complement:

MyBean code:

[code]
public class MyBean {

/** Creates a new instance of MyBean */
public MyBean() {
}

public List getValues) {
System.out.println("getValues called");
List lista = new ArrayList();

lista.add(45);
lista.add(50);

return lista;
}
}

[/code]

I'm running with Tomcat 6.0.26.

As long as i understand, as dataTable component is inside a non rendered component (panelGroup in my example) the EL "#{myBean.values}" should not be evaluated. But, as I said in previous post, El expression is called 10 times if using JSF 2 (and zero times if using JSF1.2).

Joel Weight

I don't have an answer for you on why it is calling that code within a
component that isn't rendered, but I think you'll find that myBean.values is
evaluated once for each row in the datatable, plus a couple more times for
good measure. So, with 50 rows, it would be called just over 50 times.

This is a little tangential to your question, but for when you DO want to
render the datatable, what I am doing is using an f:event with the type
preRenderComponent and calling a method to populate the data list, then in
the 'value' of the datatable tag, we use a property that simply returns the
data list. Something like this...

[code]






Bean code
public void loadData( SomeObject myParameters )
{
myDataList = someService.loadFilteredData( myParameters );
}

public List getValues()
{
return myDataList;
}
[/code]

That way, loadData is only called once, and the 50 calls to getValues is
cheap.

Joel

On Tue, Sep 28, 2010 at 2:45 PM, wrote:

> Just to complement:
>
> MyBean code:
>
> [code]
> public class MyBean {
>
> /** Creates a new instance of MyBean */
> public MyBean() {
> }
>
> public List getValues) {
> System.out.println("getValues called");
> List lista = new ArrayList();
>
> lista.add(45);
> lista.add(50);
>
> return lista;
> }
> }
>
> [/code]
>
> I'm running with Tomcat 6.0.26.
>
> As long as i understand, as dataTable component is inside a non rendered
> component (panelGroup in my example) the EL "#{myBean.values}" should not be
> evaluated. But, as I said in previous post, El expression is called 10 times
> if using JSF 2 (and zero times if using JSF1.2).
> [Message sent by forum member 'leandro_komosinski']
>
> http://forums.java.net/jive/thread.jspa?messageID=483867
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]

leandro_komosinski
Offline
Joined: 2007-08-12

Hi Joel,

I understand your solution (workaround). But, the point is: in JSF1.2 everything works fine: zero calls if dataTable won't be rendered and one call otherwise.

So, for me, JSF2 have a critical bug.

Leandro

Joel Weight

Yep Leandro, I understood that from your original email, and agree with your
assessment, which is why in my response I said I didn't know why it was
calling the function at all in a non-rendered component.

I just felt like offering the unsolicited performance tip for anyone in the
future that may be searching the forums seeing a performance problem related
to datatables.

Joel

On Fri, Oct 8, 2010 at 7:32 AM, wrote:

> Hi Joel,
>
> I understand your solution (workaround). But, the point is: in JSF1.2
> everything works fine: zero calls if dataTable won't be rendered and one
> call otherwise.
>
> So, for me, JSF2 have a critical bug.
>
> Leandro
> [Message sent by forum member 'leandro_komosinski']
>
> http://forums.java.net/jive/thread.jspa?messageID=484762
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]

leandro_komosinski
Offline
Joined: 2007-08-12

Joel,

Thank you! The tip is a great idea and works correctly.