Friday, March 5, 2010

JSF confirmation message using javascript

Problem:

When a command button is clicked, display a prompt to the user if user selects 'OK' execute the action other wise stay in the current page.

Solution:

Use javascript confirmation dialog in <commandButton>


<h:commandButton value="Save" action="#{BackingBean.save}" onclick="if (!confirm('Are you sure you want to save?')) return false" >

If we return false from the javascript the action will not be executed.

Followers