File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes validating data in client side in a web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validating data in client side in a web application" Watch "validating data in client side in a web application" New topic

validating data in client side in a web application

Nadine Hossam

Joined: Jun 19, 2005
Posts: 13
I'm developing a web application using Struts framework.

and my questions is, does the validate method int the ActionForm replaces the using javascript validation?

If I can do all the validations in this validate method, so does that mean that i'm not going to use JS at all?

For example if I need to check if a field has been entered, or for the field's length
Should I do that using JS validation, or the validate method in form bean.

if they are working the same way, so I guess it would be more efficient to be written in the ActionForm
[ July 22, 2007: Message edited by: Nadine Hossam ]
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32312

You can choose whether to do the validation instead of or in addition to the JavaScript. Many people prefer to have both as users see errors earlier. This is especially useful for required fields. If I leave out a required field, should I have to wait for a server roundtrip to find out?

For field lengths, you can use an HTML attribute to restrict length so the JavaScript is not necessary. Of course there is no harm since Struts can generate the JavaScript validation for you.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
subject: validating data in client side in a web application
It's not a secret anymore!