• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MVC and Form Validation

 
Hung Tang
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic