File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes MVC and Form Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "MVC and Form Validation" Watch "MVC and Form Validation" New topic

MVC and Form Validation

Hung Tang
Ranch Hand

Joined: Feb 14, 2002
Posts: 148
Which component is responsible for doing form validation or any type of validation? Should it be the controller or the model?
I am thinking it is up to the controller to validate the form parameters. I know this can be accomplished quite easily using JavaScript but I will refrain from using it for this task.
I am not using Struts, but I have a pretty good idea that the Action classes will do much of the validation.
Any ideas?
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
have you checked this link?
i've been using this...
hope it helps

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

In Struts the primary (field-oriented) validation is done by the "model". Which they consider a violation of what a model's for, but it works, so it doesn't really matter.
An alternative implementation has been worked out where the actual validation is done declaratively, but it's still attached to the model.
This is just part of the validation process, however. If a form fails validation, the bean is sent (back) for correction, otherwise the Action processor gets control and it can do business-rule type validation, which is to say validation where the relationships between fields is considered more closely.
In a TRUE MVC implementation -- which is something that no HTTP-based system is capable of delivering, the validation is really a controller thing, where validation can actually occur as you are inputting the data. For example, making the terminal beep and reject letters being typed into a numeric field. JavaScript can be used for that type of purpose.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: MVC and Form Validation
It's not a secret anymore!