8
votes

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>
3
Did you Ctrl+F5 the page which is opened from the work server or at least clear the browser cache on the entire domain to ensure that you've the latest version of the PrimeFaces-included CSS/JS stuff? Perhaps you upgraded PrimeFaces in the meanwhile and you've had still the old JS from the domain in your browser cache.BalusC
It is true I have updated the PrimeFaces lib to another version during the development of the application. What would you recommend me to do? Is there any thing I should do on the server side?Bart1990
As said, clear browser cache.BalusC
I'll try it first thing tomorrow when I arrive at work. Thank you so far!Bart1990
Unfortunately it didn't work. Still I think you're right it has got to do something with the update to the other Primefaces version.I also have a problem with another componenent p:Datatable: the scrollbars don't work on the application at work.Bart1990

3 Answers

16
votes

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.

4
votes

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>
1
votes
<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