It's not a secret anymore!
The moose likes JSF and the fly likes h:commandLink and onsubmit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "h:commandLink and onsubmit" Watch "h:commandLink and onsubmit" New topic

h:commandLink and onsubmit

Arine Vasan

Joined: Feb 21, 2004
Posts: 8

I have a javascript validation onsubmit of my form. When I click the
commandLink the js gets called and throws the alert for validation
failure. But the form submits even when the validation fails. Could
you please let me know if I am not using this correctly.


function validate(){
if (..){

alert('Validation Error');
return false;
return true;

<h:form id="frmSave" onsubmit="return validate();">
<h:commandLink action="#{}">
<h utputText value="Save" styleClass="button-text"/>


Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
I also had this problem with commandLink's onclick method before.

I needed to perform some JS validations on the onlick method and should continue/stop submission depending on the result.

I found out that it didn't work with commandLink, I switched to commandButton and it worked fine.

SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
I agree. Here's the link:
subject: h:commandLink and onsubmit
jQuery in Action, 3rd edition