Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2 / primefaces : p:panel not rendered with ajax?

Im not sure if this behaviour is normal or not.
Im hoping that my panel will be rendered only after clicking on a button that triggers an ajax request.

Not using Ajax works fine :

  1. p:panel id="myPanel" rendered="#{myBean.flag}"
  2. p:commandButton ajax="false" action="#{myBean.setFlagToTrue}"
  3. before clicking the button, the myPanel is not displayed (flag = false)
  4. clicking the button, will set the flag to true, and myPanel is rendered fine

Using ajax fails :

  1. p:panel id="myPanel" rendered="#{myBean.flag}"
  2. p:commandButton ajax="true" action="#{myBean.setFlagToTrue}" update="myPanel"
  3. before clicking the button, the myPanel is not displayed (flag = false)
  4. clicking the button, will set the flag to true (as displayed by my log file), and myPanel is not rendered

I've tried omitting the rendered attribute, and indeed the ajax works fine.
I can tell that by looking at the changes reflected inside the panel.

like image 730
Albert Gan Avatar asked Dec 24 '10 10:12

Albert Gan


1 Answers

put your panel with conditional rendering inside another and update it. Like this:

<p:outputPanel id="toUpdate">
  <p:panel id="myPanel" rendered="#{myBean.flag}">
  </p:panel>
<p:outputPanel>

<p:commandButton update="toUpdate"/>

This is a known issue. The element can't be updated if it doesn't exist in DOM.

like image 142
Vladimir Ivanov Avatar answered Nov 19 '22 13:11

Vladimir Ivanov