views:

57

answers:

2

Hi,

I'm developing a web interface with seam/richfaces.

Alot of the components has something akin to

<h:panelGrid rendered="#{complexbean.heavyoperation()}">
    ...
</h:panelGrid>
<h:panelGrid rendered="#{!complexbean.heavyoperation()}">
    ...
</h:panelGrid>

In this case the #{!complexbean.heavyoperation()} gets evaluated twice.

My question is, is there anything similar to if-else statements I can use in the page to avoid these multiple evaluation of the same EL (and I would like to avoid any uses of JSP stuff, i.e. %<% if ... %>% )?

Thanks!

A: 

If you have nothing against jstl, you can use c:choose/c:when/c:otherwise construction.

spbfox
Avoid using JSTL at all cost when using Facelets. You need to know what you are doing if you use JSTL tags, because of the way Facelets work.
Shervin
You need to know what you are doing all the time, do not you?
spbfox
No, not if you stay away from JSTL. Specifially the c:forEach tag and how it is rendered compared to Facelets, which is compile time versus runtime.
Shervin
+4  A: 

I see you are using Seam. Can't you just use a @Factory in one of your backing beans? In the same scope it will be evaluated only ONCE. This is its purpose.

@Factory("operation")
public bool heavyComputation() {
    return true;
}

And then your view:

<h:panelGrid rendered="#{!operation}">
    ...
</h:panelGrid>
<h:panelGrid rendered="#{!operation}">
    ...
</h:panelGrid>

I think this is much clearer. Hope that helps:)

Petar Minchev