6

We're developing a Java web app that utilizes JSF (Richfaces through Seam) for its UI. I've read several articles that indicate that using the "rendered=" attribute on UI components results in a pretty substantial performance hit. We have several components that we'd like to enable or disable based on whether or not their values are set. For example, if we're displaying an item for sale we wouldn't have a bunch of blank fields for attributes that are not set.

Given this performance hit, however, we're apprehensive about using multiple "rendered" fields. Is there a better performing alternative to this? Is there anything we can do to improve the performance of using this field?

Shadowman
  • 11,150
  • 19
  • 100
  • 198
  • 3
    I'd be interested in links to articles illustrating the performance hit of the `rendered` attribute... – Dolph Jun 29 '10 at 14:30
  • I'd be interested in the profiler results of your webapp as well. Hint: [VisualVM](https://visualvm.dev.java.net/) + [JMeter](http://jakarta.apache.org/jmeter/). – BalusC Jun 29 '10 at 14:46
  • Once such article is here, particularly the section on "The Cost of Conditional Rendering"... http://www.jsfcentral.com/articles/speed_up_your_jsf_app_1-2.html We haven't done any substantial profiling ourselves. We haven't gotten to much of the UI programming yet, but wanted to make sure that we're tackling it the right way when we do. – Shadowman Jun 29 '10 at 14:53

3 Answers3

4

If the getter does nothing else than just returning a (cached) boolean property, then I really don't see any pains. There's no alternative to it. Best what you could to to improve the performance is to cache it in either the model (lazy loading) or the view (c:set). The cost of getter method invocation in turn is fully negligible.

PermGenError
  • 45,977
  • 8
  • 87
  • 106
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Any other way wouldn't be free anyways.. so I would just use the standard JSF way to hide/show components.

Max Katz
  • 1,582
  • 1
  • 9
  • 5
0

You can use the style="display : (#{bean.booleon} ? block : none)" JSF tag.

Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99
TaherT
  • 1,285
  • 2
  • 22
  • 41
  • But then it´s code is in the html page. With rendered attribute it´s even not in the html code! – marcel Sep 25 '15 at 11:02