This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "h:commandLink and onsubmit" Watch "h:commandLink and onsubmit" New topic
Author

h:commandLink and onsubmit

Arine Vasan
Greenhorn

Joined: Feb 21, 2004
Posts: 8
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


SCJP, SCWCD, SCMAD, SCEA-1
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%)
 
Consider Paul's rocket mass heater.
 
subject: h:commandLink and onsubmit
 
Similar Threads
Javascript problem
client side validation in struts
how to call different managed beans action dynamically ?
js event help
Submitting a form from a javascript method gives javax.faces.el.EvaluationException