Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces confirm dialog disappearing almost instantly

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>
like image 590
Bart1990 Avatar asked Feb 01 '12 20:02

Bart1990


3 Answers

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.

like image 198
Adam Avatar answered Oct 10 '22 23:10

Adam


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>
like image 28
Endre Avatar answered Oct 10 '22 21:10

Endre


<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

like image 27
Praveen Avatar answered Oct 10 '22 22:10

Praveen