views:

834

answers:

1

The struts2 validation framework allows you to define your validation for an action or at the domain object level.

My question is, is there an advantage or disadvantage using one over the other? What do you recommend?

My own findings: You may use the same domain objects in several actions and may have to re-define validation rules per action...maybe its better to place the validation rules in the object. But, I feel uncomfortable placing validation rules at the domain level since it seems to be something that belongs in the action.

+1  A: 

In the MVC architecture the validation should be done at the model level i.e. domain objects. I don't think it's appropriate to have validation logic in controllers (Actions).

John Topley
My thoughts were, decisions are made based on validation and that sounded like a controller but you are right. The controller will still make the decision based on the validation specified in the model. Thanks.
Vincent Ramdhanie