onclick validation and action for a4j:commandbutton
843844Oct 15 2009 — edited Oct 15 2009Hi, I have a requirement: when i click on a button, it has to show ok/cancel dialog box and if it is ok, then we have to call server code in ajax manner, else just be there doing nothing.
I implemented like below:
Case 1:
JSF code:
<a4j:commandbutton id="id1" value="Delete" onclick="showValidation()" action="#{bbean.deleteAction}" />.
JS code:
function showValidation()
{
if(confirm("Are you sure you want to delete?"))
return true;
else
return false;
}
It showed me the validation, but irrespective of Ok/Canel button that i clicked, the action's bbean.deleteAction gets executed.
I changed the JSF Code a little by providind return in the onclick as below,
Case 2:
<a4j:commandbutton id="id1" value="Delete" onclick="return showValidation()" action="#{bbean.deleteAction}" />.
This time, It showed me the validation, but irrespective of Ok/Canel button that i clicked, the action's bbean.deleteAction is NOT executed
I have tried several combinations, but no use. can anyone in the java world help me resolviing this issue? Thanks in advance and any small help in acheving my task is greatly appreciated.