Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF render phase (why is my code being executed?)

Tags:

jsf

jsf-2

I'm currently investigating the performance of a JSF application. I have noticed that code is being executed even though rendered is set to false. For example, take this piece of code:

<h:panelGroup rendered="#{bean.render}">
    <my composite component here/>
</h:panelGroup>    

Even though #{bean.render} returns false, I can clearly see from debug logs, that the code for my composite component is being executed during the render phase. It also looks like the code is being executed before #{bean.render} is even called. It isn't rendered in the HTML returned to the client, but it still appears that the server is executing the code.

Can anyone explain this?

Thanks.

like image 351
Chris B Avatar asked Dec 14 '12 21:12

Chris B


2 Answers

Composite components are built during render response phase. JSF needs to populate the component tree first and then generate HTML based on the component tree. You're inside the composite component apparently referencing some bean properties which are mandatory to be evaluated during view build time.

If you'd like to conditionally control the building of the composite component instead of the rendering, then you need to use a conditional view build time tag instead of the rendered attribute. JSTL offers the <c:if> and <c:choose> for that.

<c:if test="#{bean.build}">
    <my:composite />
</c:if>

See also:

  • JSTL in JSF2 Facelets... makes sense?
like image 180
BalusC Avatar answered Jan 28 '23 10:01

BalusC


Jsf have to know if your components are rendered or disabled or whatever. Let say you say disabled="false" it is shown on clint side and client may change value and submit the form, even though javascript is disabled by the client, jsf checks it's disabled false or true on server side. if it was true it is not acceptable and never comes to your bean because of process validation phase of jsf, same as rendered="false"

like image 28
Kerem Can Kurtay Avatar answered Jan 28 '23 10:01

Kerem Can Kurtay