0

I have a dialog thus:

        <p:dialog id="pinDialog" widgetVar="pinDialog" width="800" binding="#{userBean.pinCheckDialog}" closable="false" modal="true" closeOnEscape="false" showEffect="clip" hideEffect="clip">
            <h:form id="pinEntry">
                <p:messages for="messagesForPinCheck"/>
                <p:outputLabel for="pinCode" value="#{messages.PinCodeRequired}"/>
                <p:inputText value="#{userBean.enteredPin}" size="4" id="pinCode"/>
                <p:commandButton value="#{messages.PinCodeSubmit}" update="@form" action="#{userBean.submitPin()}"/>
            </h:form>
        </p:dialog>

And within a idleMonitor I am calling active() and idle() on the userBean. If the user goes idle and other conditions hold true I want to show the pinDialog:

        if (isPinRequired()) {
            logger.debug("pin required, attempting to show pin dialog");
            RequestContext.getCurrentInstance().execute("pinDialog.show()");
        }

The log message appears, but nothing happens on screen. I have also tried PF('pinDialog').show without success. What am I doing wrong?

Cœur
  • 37,241
  • 25
  • 195
  • 267
jmkgreen
  • 1,633
  • 14
  • 22

1 Answers1

0

If you want to show a dialog at another time besides page load, then you will want to use the 'render' attribute on the dialog form.

<p:panelGroup id="mainPanel">
   <p:dialog rendered="#{myBean.showForm}"
   </p:dialog>
</p:panelGroup>

Where showForm is a boolean function in your backing bean returning false normally.

Without the outside p:panelGroup and p:dialog normally rendering false, it would never show up even when render was set to true.

j.con
  • 879
  • 7
  • 19
  • That conflicts with the answer from [JSF Conditional Rendering](http://stackoverflow.com/questions/10385278/jsf-conditional-rendering) where rendered must be initially true (the default) for any operations subsequently to find it. With it false, no HTML will be produced by the server for Javascript DOM operations to find it. – jmkgreen Mar 18 '14 at 17:21
  • @jmkgreen that is why I have the outside p:panelGroup, in that case all the html gets built with the dialog not rendering... here is copy/paste from that link you gave me "You need to wrap it in a container component which is always rendered and thus always available in the HTML DOM tree." – j.con Mar 18 '14 at 17:23
  • So JSF sends HTML to the browser (sans the dialog). Next we execute what within the bean? Can't use `RequestContext.getCurrentInstance().execute("pinDialog.show()");` as the browser no longer has the `pinDialog` in the DOM tree. Are you suggesting that we can dynamically set `rendered` on the dialog and it will appear inside the browser? – jmkgreen Mar 18 '14 at 17:28
  • Maybe my way would be over complicated, but have you followed the http://www.primefaces.org/showcase/ui/idleMonitor.jsf tutorial? Your example looks a little different. Also you have a h:form inside your p:dialog, which I can only assume sits inside another h:form, which means you'll have nested forms, which is a bad thing. Try removing the form tag – j.con Mar 18 '14 at 17:39
  • Yes I've been testing against the tutorial. I have been burnt by embedded forms before many years ago. Right now I am converting the `idleMonitor` to use `p:ajax` in the hope I can open the dialog client side. – jmkgreen Mar 18 '14 at 17:45