Dump Javascript Confirmation

confirm

There are traditional ways to display confirmation dialogs both in web and desktop applications. For example with swing JOptionPane showConfirmDialog can display a confirmation box to the user. On the other side, the legacy solution is to use javascript confirm function by attaching it an an event like onclick=”return confirm(‘You sure?’)”; Problem is confirm boxes are ugly, lacks customization support and may be blocked by browsers. A much better way to display confirmation dialogs is to use overlay dialogs, preferably modal ones. In PrimeFaces, confirmDialog component provides an easy and  customizable way for the requirement. Since the most common use case is use a button and displaying confirmation box, primefaces button has a built-in conformation support.

Old way;

	<h:commandButton value="Delete" action="#{bean.delete}" onclick="return confirm('Are you sure you want to delete')" />

PrimeFaces way;

<p:button value="Delete" action="#{bean.delete}">
<p:confirmDialog message="Are you sure you want to delete" />
</p:button>

Compared to javascript confirmation, confirmDialog is highly customizable, yes and no button labels, message, severity icon, the dialog look and feel itself and more.

Online Demo

Check out the online demo to see confirmDialog in action.

Comments are closed.

%d bloggers like this: