Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

onclick validation and action for a4j:commandbutton

843844Oct 15 2009 — edited Oct 15 2009
Hi, 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 12 2009
Added on Oct 15 2009
2 comments
616 views