Tmss G-ils
Tmss G-ils

Reputation: 153

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>

Upvotes: 0

Views: 1939

Answers (2)

Newton fan 01
Newton fan 01

Reputation: 514

I have hit the same problem. My solution was to display the current time inside the element that i want to be rendered.

If, for instance, you want to render a panel, just paste inside that panel the following snippet:

<h:outputText value="#{session.lastAccessedTime}"> 
    <f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss.SSS" type="date" /> 
</h:outputText> 

If the time is updated after button click, then obviously the component was rendered. But is the opposite also true? If the time is not updated, does this mean the component was not rendered? What if the component got rendered properly, but the time displayed is frozen to the moment the page was first accessed? I had small doubts about that, so i refreshed the page, and the time changed. So the time displayed is not frozen to the initial moment.

Also note that there are multiple ways to get the time; if you don't like to use session time, you could set a property in the backing bean, and initialize it to new Date()

Upvotes: 0

BalusC
BalusC

Reputation: 1108632

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:

Upvotes: 1

Related Questions