aspose file tools*
The moose likes Struts and the fly likes Using Javascript in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using Javascript in Struts" Watch "Using Javascript in Struts" New topic
Author

Using Javascript in Struts

Vijay Jayaraman
Greenhorn

Joined: Sep 18, 2002
Posts: 9
Is there anyway out to use javascript in JSP's designed in a struts framework using the tags provided by struts.
Will there not be a performance overhead if we move all our client side validations to the Action Class?
Ravi Veera
Ranch Hand

Joined: Jun 23, 2001
Posts: 127
Yes you can use javascript with struts tags. If you look at the tags you will see that they provide all the parameters that the regular HTML tags provide.
With the Validator plugin you can do both client sode as well as server side validations. The validator plugin generates the required Javascript for you.
It makes sense to have serverside validations because Javascript can be turned of on the browser. Or your client may be used in an enviroment where Javascript is not supported (Think Handhelds,cellphones,Any OS with no Javascript support,...).
I usually do basic validations on the client side like required field and numbers fall in a range. On the server side I do all the basic validations plus checking for duplicates and enforcement of other business rules.
Checking if a few strings are empty and that they fall within a particular range isn't going to overload your system
Regards
Ravi
Vijay Jayaraman
Greenhorn

Joined: Sep 18, 2002
Posts: 9
Thanks for you response.Can you please elaborate to me on where to get the validator plug-in and a simple example where you have used javascript for a client side validation(for instance password not entered on the password field of a login form).
Note:
the way i am handling it at present is like i am going to my action class and validating it rather than validating for it on the client side itself.
Ravi Veera
Ranch Hand

Joined: Jun 23, 2001
Posts: 127
Here's a link that will help. I have struts 1.02 running and got the validator plugin from here and installed it a few months ago.
The Validator is now a core part of the Struts 1.1b2 distribution and certain elements have changed. Unfortunately the documentation has not caught up with the changes and there is no simple how-to (yet) on how to use it.
HTH
Ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Javascript in Struts