1

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");
    }
}
Community
  • 1
  • 1
wst
  • 4,040
  • 4
  • 41
  • 59

1 Answers1

1

Maybe you can hide that close button:

closable="TRUE"

or maybe you can update variable through onHide attribute.

I just noticed that dialog is not in FORM?

found similar post HERE

And here is I think hint for you, which gave me answer: just add oncomple="someDialog.show()" event to buttons and widgetVar="someDialog" to dialog as I understand close changes rendered attribute, thats why you can't show it.

Community
  • 1
  • 1
Darka
  • 2,762
  • 1
  • 14
  • 31
  • Setting `closable` does not change anything. Also `dialog` does not have to be inside `form`. I know about `oncomplete="dialog.show()"` but I wanted to enable or disable dialogs from the bean. Then I checked [question](http://stackoverflow.com/questions/17381652/primefaces-dialog-not-reopening-when-ajax-close-event-listener-included) you found, and that did it. Thanks. – wst Sep 04 '13 at 15:10