• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation in ActionForm or ActionClass

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends ,

We can perform validations in ActionForm using validate() method (using ActionErrors ). We can also validate in Action class using ActionErrors .

My question is that for performing validations how do we decide that we have to validate from ActionForm or ActionClass . When should the validations be performed through ActionClass or ActionForm ?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question!

Here's my general rule of thumb: If it's a simple validation such as testing for existence, whether it's an integer, valid date format, etc., put it in the validate() method of the ActionForm. If it's something that could be described as a "business rule", it should be done in the action class, and the actual verification logic should go in a class that is part of the "model" layer of your MVC application.

For example, if a password input cannot be blank, that's a simple rule and can be done in the validate method. If a password has to have at least one upper-case character and one numeric character, but cannot start with a numeric character, that's a business rule, and should be done in the Action class with the rule itself coming from a model-layer class.

The point of making this distinction is to preserve the integrity of the MVC model.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Merrill's suggestion. To take his example a step further. Say you have to validate that the entered password does not match any of the user's previous 8 passwords. There is no way that you would want to implement this type of validation in the form.

- Brent
 
kumar shinde
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You very much Merrill Higginson and Brent Sterling

Now I am able to make distinction about validations....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic