Solution here. (Showing and hiding dialog
from within bean.)
I have a dialog
and show/hide buttons which works fine. Dialog reads boolean
value from backing bean and updates it's visible
attribute (which makes it show or hide). Everything works fine until I close dialog using default close button, which fires ajax close
event. From that moment on show/hide buttons does not work, or rather dialog does not update it's visible
state. It stays closed forever.
I found out that, after ajax event is fired, everything updates correctly except dialog visible
attribute. Buttons works fine, they updates backing bean correctly (I can see it in log file), and also dialog panel is updated correctly (I can see correct showDialog
value displayed on screen).
I know there are other ways to show/hide dialogs, yet I am really curious what is happening in this case - why it works that way? Is there any way to display dialog by reading visibility value from bean (and what's more important to update bean value when dialog is closing)?
My XHTML:
<h:form>
<p:commandButton value="show d1" actionListener="#{testBean.enableShowDialog()}" update=":dialogId"/>
<p:commandButton value="hide d1" actionListener="#{testBean.disableShowDialog()}" update=":dialogId"/>
</h:form>
<p:outputPanel id="dialogId">
showDialog value = #{testBean.showDialog}
<p:dialog header="d1" visible="#{testBean.showDialog}">
<p:ajax event="close" listener="#{testBean.disableShowDialog()}" update=":dialogId"/>
test
</p:dialog>
</p:outputPanel>
And backing bean:
@ManagedBean
@ViewScoped
public class TestBean implements Serializable {
private static final Logger LOGGER = LoggerFactory.getLogger("TB");
private boolean showDialog;
public boolean isShowDialog() {
LOGGER.info("getter isShowDialog={}", showDialog);
return showDialog;
}
public void enableShowDialog() {
showDialog = true;
LOGGER.info("isShowDialog set to true");
}
public void disableShowDialog() {
showDialog = false;
LOGGER.info("isShowDialog set to false");
}
}