Search code examples
jsfjsf-2render

A way to easily check if an element was rendered in jsf2


I have a button that is supposed to close a modal panel and render several elements.

Is there an easy way to check if an element was rendered after the button was pressed?

example button:

<a4j:commandButton onclick="#{rich:component('modal')}.hide();"  
    style="background-repeat:no-repeat;width:18px;height:18px;" 
    image="includes/images/close.gif"       
        render=":id1 :id2">
        <f:setPropertyActionListener target="#{Controller.attribute}" value="false" />
</a4j:commandButton>

Solution

  • I have another button that does not "work" on the un-rendered div.

    The conditon of the rendered attribute of all of the button's parent components must be preserved when you're submitting the form. So it should not only evaluate true during the request of presenting the form with the button, but it should also evaluate true during the request of processing the form submit. Easiest is to put the backing bean in the view scope by @ViewScoped.

    Also, if you're re-rendering a component which in turn contains a <h:form>, you need to explicitly add the client ID of that <h:form> to the render attribute. E.g. when component with client ID id1 has in turn a <h:form id="formOfId1">.

    render=":id1 :id2 :formOfId1"
    

    You can debug this all by just exploring the HTTP traffic in the webbrowser's developer toolset (press F12 in Chrome/IE9/Firebug and check the "Network" section).

    See also: