Spring MVC: Where to place validation and how to validation entity references.
Posted
by arrages
on Stack Overflow
See other posts from Stack Overflow
or by arrages
Published on 2010-04-12T17:29:26Z
Indexed on
2010/04/12
17:33 UTC
Read the original article
Hit count: 180
Let's say I have the following command bean for creating a user:
public class CreateUserCommand {
private String userName;
private String email;
private Integer occupationId;
pirvate Integer countryId;
}
occupationId and countryId are drop down selected values on the form. They map to an entity in the database (Occupation, Country).
This command object is going to be fed to a service facade like so:
userServiceFacade.createUser(CreateUserCommand command);
This facade will construct a user entity to be sent to the actual service. So I suppose that in the facade layer I will have to make several dao calls to map all the lookup properties of the User entity.
Based on this what is the best strategy to validate that occupationId and countryId map to real entities? Where is the best place to perform this validation? There is the spring validator but I am not sure this is the best place for this, for one I am wary of this method as validation is tied to the web tier, but also that means I would need to make the dao calls in the validator for validation but I would need to call the dao's in the facade layer again when the command -> entity translation occurs.
Is there anything I can do better?
Thanks.
© Stack Overflow or respective owner