Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

h:commandLink and onsubmit

 
Arine Vasan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

SCRIPT:

function validate(){
if (..){

}else{
alert('Validation Error');
return false;
}
return true;
}

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

Thanks,
Aruna
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic