Reputation: 23
I need create dynamic confirmDialog. I have a dynamicallly created CommandButton. So when it press, confirmDialog will show. I do not know how to show it on CommandButton pressed.
Upvotes: 1
Views: 2032
Reputation: 461
Your button should be like this:
<p:commandLink oncomplete="confirmation.show()"
action="#{campagneComtroller.messageDeleteCam1(c)}"
update=":frmDlgDel:confirmDialog">
<p:graphicImage value="/image/delete.png" height="20" width="20"/>
</p:commandLink>
Your confirmDialog should be like this:
<h:form id="frmDlgDel">
<p:confirmDialog id="confirmDialog"
message="#{campagneComtroller.messageDeleteCam1}"
header="#{bundles.messages['message.SupprimerGeneral']}" severity="alert" widgetVar="confirmation">
<p:commandButton id="confirm" value="#{bundles.messages['message.OuiSure']}" oncomplete="confirmation.hide()" update=":formCam :frmDlgDel"
actionListener="#{campagneComtroller.deleteCam1()}" />
<p:commandButton id="decline" value="NonPasEncore" onclick="confirmation.hide()" type="button" />
</p:confirmDialog>
</h:form>
Your java code should be like this:
public void messageDeleteCam1(Cam cam) {
conditionVerified = true; // ... you can put here your treatments
if (conditionVerified) {
messageDeleteCam1 = "this cam is bla bla bla ";
} else {
messageDeleteCam1 = "are you sure to delete this cam ?";
}
}
NB: we have used here oncomplete + update, that's why we could see the difference in the confirmDialog after java treatments.
Upvotes: 2