I'm developing an application in JSF 2.0. I'm also using the Primefaces component library. I'm having a problem with the p:confirmDialog of Primefaces. As soon as I want to show a p:confirmDialog, it disappears again almost instantly. The weirdest thing is that this problem only occurs with the application that is deployed on the GlassFish Server at work. When I upload the very same .war file to the GlassFish server on my computer at home or when I run the application in Netbeans this problem does not occur. I really can't find out what the cause of this problem is. Also I couldn't find any information about this on Google. Any help would be greatly appreciated! This is my code:
<h:commandButton value="Verwijderen" onclick="bezoekConfirmation.show()" styleClass="verwijderKnopBig" rendered="#{pageRenderController.canWriteBezoekenMobiele}" />
<p:confirmDialog message="Bent u zeker dat u dit bezoek wilt verwijderen?" closable="false"
header="Bezoek verwijderen" severity="alert" widgetVar="bezoekConfirmation">
<p:commandButton value="Ja" oncomplete="bezoekConfirmation.hide()" action="#{bezoekenMobieleController.deleteBezoek}" ajax="false" />
<p:commandButton value="Nee" onclick="bezoekConfirmation.hide()" type="button" />
</p:confirmDialog>
Clicking on the button will cause a submit. The dialog appears, and the page is reloaded immediately.
Change this:
bezoekConfirmation.show()
to this:
bezoekConfirmation.show(); return false;
It's really strange that your version works on your computer at home.
The solution with return false;
will only work if you do not intend to call a method or set a variable.
In this case, just use oncomplete="dialog.show();"
instead of onclick="dialog.show();"
This will pass through the method call.
Example:
Given that the following code is in some kind of data table then you can have
<p:commandButton value="edit" update=":dialog" oncomplete="dialog.show();">
<f:setPropertyActionListener target="#{bean.field}" value="#{_item}" />
</p:commandButton>
or call the setter directly
<p:commandButton value="edit" update=":dialog" oncomplete="dialog.show();" action="bean.setField(_item)">
</p:commandButton>
<h:commandButton value="Verwijderen" onclick="bezoekConfirmation.show()" styleClass="verwijderKnopBig" rendered="#{pageRenderController.canWriteBezoekenMobiele}" />
<p:confirmDialog message="Bent u zeker dat u dit bezoek wilt verwijderen?" closable="false"
header="Bezoek verwijderen" severity="alert" widgetVar="bezoekConfirmation" appendToBody="true">
<p:commandButton value="Ja" oncomplete="bezoekConfirmation.hide()" action="#{bezoekenMobieleController.deleteBezoek}" ajax="false" />
<p:commandButton value="Nee" onclick="bezoekConfirmation.hide()" type="button" />
</p:confirmDialog>
appendToBody="true"
will overcome your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With