jsf-2.2mojarratomee-7

Why does h:link value call bean method when the control is not rendered?


I have this on my JSF page

<h:link rendered="false" value="${mybean.status}" />

The control is not rendered but it still calls getStatus() method in mybean. Why?

The problem seems to be only with value attribute because If I include href="${mybean.url}" then getUrl() method does not get called.

I'm using TomEE 7.04 plume which comes with Mojarra 2.2.12.


Solution

  • As the documentation says about the rendered attribute:

    Flag indicating whether or not this component should be rendered (during Render Response Phase), or processed on any subsequent form submit.

    It means that the rendered attribute is processed in the last lifecycle phase (Render Response Phase) while the value of the component was set during the Update model values Phase. In case of a fresh (GET) request, it is being set also in the Render Response Phase but clearly prior to checking the rendered attribute. And setting the component's value means calling the getter.

    There is no href attribute in the h:link that's why no getter was called in this case.

    As a workaround, you could wrap your h:link in f:subview which uses the rendered attribute in an earlier phase.

    <f:subview rendered="false">
        <h:link rendered="false" value="${mybean.status}" />
    </f:subview>
    

    You may want to look at this question, its answer and comments, there are links to the JSF lifecycle and maybe other useful information.