You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mississippi John Hurt <jo...@gmail.com> on 2006/08/16 03:55:21 UTC

Validator Client-Side and Custom Classes

Hi,
I want to do client-side validation using a custom class I can specify in
the validator.xml <validator><classname/></validatior> section. But my
question is if I use a custom class, then how the heck can Struts generate
the custom javascript for it in the jsp if I'm using a custom java class I
wrote that exists only on the server?  Not possible right?

So if that's the case, if you do leave some custom classname validator class
in your validation.xml, then will that validation simply be ignored?

Thanks for help with these 2 questions.

Re: Validator Client-Side and Custom Classes

Posted by Scott Van Wart <sc...@indosoft.com>.
Mississippi John Hurt wrote:
> Hi,
> I want to do client-side validation using a custom class I can specify in
> the validator.xml <validator><classname/></validatior> section. But my
> question is if I use a custom class, then how the heck can Struts 
> generate
> the custom javascript for it in the jsp if I'm using a custom java 
> class I
> wrote that exists only on the server?  Not possible right?
>
> So if that's the case, if you do leave some custom classname validator 
> class
> in your validation.xml, then will that validation simply be ignored?
>
> Thanks for help with these 2 questions.
>
If you look at the source for commons-validator, you'll see a package 
called 'org.apache.commons.validator.javascript'.  It has a bunch of .js 
files as package resources, so you might look at the sources for those 
to get started.  Beyond that I don't have any experience with it (I 
personally can't stand client-side validations, as validation has to be 
done in the database, and on the server side, and I feel inclined to 
draw the line somewhere given a choice :).

The 'validateUtilities.js' seems to have a lot of functions that the 
other .js files make use of, so you should probably do so as well.  It 
also looks like the .js file name, and function name inside the file 
match the method name of your validation routine (with a 'form' 
parameter passed, which is likely an array?).  So if you do all this, I 
would imagine the validator will pick it up automatically (and fail 
silently and ignore it if you don't, as you mentioned above).

Good luck,
  Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org