I'm trying to conditionally pop up a dialog in Primefaces 5.0 without using the backend via a <p:commandButton>
.
I've looked here, here, and here and tried each of the offered solutions, but none of them work.
The problem I'm running into is how to get the dialog to show up on the page when you click the button; everything seems to be going smoothly up until then.
The XHTML for the buttons:
<c:choose>
<c:when test="#{businessLayer.context eq 'REF_INFO'}">
<p:commandButton value="Submit PA"
disabled="#{outcomes.size() eq 0 or businessLayer.ticket eq null}"
onclick="PF('refInfoDialog').show()"
actionListener="#{businessLayer.splund('submitting ref info pa')}"
type="button"/>
<!-- onstart="PF('loadingResults').show()"
onerror="PF('errorDialog').show()"
oncomplete="PF('loadingResults').hide(); PF('refInfoDialog').show()"-->
</c:when>
<c:when test="#{businessLayer.context eq 'FAXBACK'}">
<p:commandButton value="Submit PA"
disabled="#{outcomes.size() eq 0 or businessLayer.ticket eq null}"
onclick="PF('faxBackDialog').show()"
actionListener="#{businessLayer.splund('submitting faxback pa')}"
type="button"/>
<!-- onstart="PF('loadingResults').show()"
onerror="PF('errorDialog').show()"
oncomplete="PF('loadingResults').hide(); PF('faxBackDialog').show()"/>-->
</c:when>
<c:otherwise>
<p:commandButton value="Submit PA"
disabled="#{outcomes.size() eq 0 or businessLayer.ticket eq null}"
onstart="PF('loadingResults').show()"
onerror="PF('errorDialog').show()"
oncomplete="PF('loadingResults').hide()"
actionListener="#{businessLayer.splund('submitting regular pa')}"/>
</c:otherwise>
</c:choose>
One of the dialogs:
<p:dialog widgetVar="refInfoDialog"
id="refInfoDialog"
closable="true"
draggable="false"
resizable="false"
showHeader="true">
<h:outputLabel for="refInfoInput" value="Ticket ID"/>
<h:inputText id="refInfoInput"/>
<p:commandButton value="OK"
onstart="PF('loadingResults').show()"
onerror="PF('errorDialog').show()"
oncomplete="PF('loadingResults').hide(); PF('refInfoDialog').hide(); _SUBMIT_REF_INFO()"/>
<p:commandButton value="Cancel"
onstart="PF('loadingResults').show()"
onerror="PF('errorDialog').show()"
oncomplete="PF('loadingResults').hide(); PF('refInfoDialog').hide()"/>
</p:dialog>
#{businessLayer.splund(...)}
is a logging function in the backend for debugging purposes, and the dialogs are defined in the same form element as the buttons.
The loadingResults
and errorDialog
dialogs show up as they are supposed to, when they're supposed to, but I can't get refInfoDialog
or faxBackDialog
to show up at all. I've tried putting PF('<dialog_name>').show()
in various onclick=""
, oncomplete=""
, actionListener=""
, and onstart=""
, but it hasn't caused either of them to show up when their respective button is clicked.
UPDATE:
Turns out the onclick event is firing fine, but for some reason the dialog is being displayed behind other divs because it's outside the parent div. Isn't JSF wonderful? /sarcasm