File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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?
Thanks
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
have you checked this link?
http://www.javaworld.com/javaworld/jw-03-2000/jw-0331-ssj-forms.html
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: 15956
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
wood burning stoves
 
subject: MVC and Form Validation
 
Similar Threads
Form Level Error Messages In JSF
design advaice for data validation
Where To Locate Data Binding and Validation
Have any problem using validator
Validating some extra fields of action form not in my jsp?