RichFacesConfirmationOnClick

How to use javascript window.confirmation with onclick on a4j : commandLink

 

<a4j:commandLink onclick="if (! window.confirm('Are you sure?') ) {return false}" ...... 

 

Explanation of syntax

 

First Example:

 

<div onclick="window.confirm('sure?');alert('you are sure!')" >Click Me</div>     

 

The alert is shown always. Does not matter, what you click in the confirmation box.

 

Second example:

 

<div onclick="return window.confirm('sure?');alert('you are sure!')" >Click Me</div>     

 

The alert is not shown. Never. Just because, you say return in the first statement. Does not matter, what is returned. If JS interpretor sees a return, it stops the function and returns.

 

RichFaces puts your code (in this case the window.confirmation() ) in front of the Ajax call.

 

What to do with the second example to make it workable like it is expected?

 

Try:

 

<div onclick="if (! window.confirm('sure?')) { return false }; alert('you are sure!')" >Click Me</div>