JavaScript validation in JSF

HI,I want to do the normal javascript validation when clicking on <c:command button/>, but it always submit the values to the server. how can i make it normal button so that i can do the validation in javascript and then submit
[247 byte] By [KrishnaSa] at [2007-11-27 1:25:18]
# 1
If you understand Javascript, then you should know that "return false;" after the event will prohibit the form being submitted.This has nothing to do with JSF tho, but just with basic HTML/JS knowledge.
BalusCa at 2007-7-12 0:17:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
There are also a few projects that make JSF validation both server and client side. Off the top of my head, there's MyFaces Trinidad, Shale, and I think there was something in the MyFaces Tomahawk Sandbox.Google for JSF client side validation.
guy.colemana at 2007-7-12 0:17:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

HI Balu,

I can understand JavaScript. but the problem is see the following code :

<h:commandButton onclick="validate('val')" value="Next" action="#{ld90Bean.next}"/>

onclick event i am calling the validate method todo validations. but even the validation fails its submiting.

KrishnaSa at 2007-7-12 0:17:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

You've got to return false from the onlick if you don't want the button to submit.

<h:commandButton onclick="return validate('val')" ... />

validate(val) {

... do validation ...

if (validates) {

return true;

} else {

return false;

}

}

guy.colemana at 2007-7-12 0:17:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
> I can understand JavaScript. Really? :) I even had hinted you about returning false though ..Well, Guy Coleman provided the basic solution.
BalusCa at 2007-7-12 0:17:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Thanks Balu..now its working
KrishnaSa at 2007-7-12 0:17:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...