I want to add confirmation dialog befor editing a row or how to prompt user a confirmation befor any action. which dialog should I use for below code.
<h:commandLink value="EditPage" action="#{countryBean.editCountryByCountryCode(true)}" class="edit_icon" >
<f:setPropertyActionListener target="#{countryBean.editCountryId}" value="#{countryLang.countryCode}" />
</h:commandLink>
In the most simple way, you can use the confirm() function in an inline onclick handler.
The confirm() method displays a dialog box with a message, an OK button, and a Cancel button. The confirm() method returns true if the user clicked "OK", otherwise false .
JavaScript users can create the confirm box using the . confirm() method, which contains the confirmation message string, ok, and cancel button. The programmer can't change the confirm box style and button label if they use the default confirm box.
Alert box is used if we want the information comes through to the user. Confirm box is used if we want the user to verify or accept something. 2. You need to click “OK” to proceed when an alert box pops up.
A simple way, using a simple javascript:
<h:commandLink onclick="if (! confirm('Really want to do that?')) return false"
value="EditPage" action="#{countryBean.editCountryByCountryCode(true)}" class="edit_icon" >
<f:setPropertyActionListener target="#{countryBean.editCountryId}" value="#{countryLang.countryCode}" />
</h:commandLink>
You can use Primefaces Confirm dialog <p:confirm/>
for this purpose. You can find example showcase here.
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