spring mvc nested model validation

Posted by hguser on Stack Overflow See other posts from Stack Overflow or by hguser
Published on 2012-09-03T08:47:48Z Indexed on 2012/09/03 15:38 UTC
Read the original article Hit count: 242

Filed under:
|
|

I have two models : User,Project

public class Project{
    private int id;
    @NotEmpty(message="Project Name can not be empty")
    private String name;
    private User manager;
    private User operator;
    //getter/setter omitted
}

public class User{
    private int id;
    private String name;
    //omit other properties and getter/setter
}

Now, when I create a new Project, I will submit the following parameters to ProjectController:

projects?name=jhon&manager.id=1&operator.id=2...

Then I will create a new Project object and insert it to db.

However I have to validate the id of the manager and operator is valid,that's to say I will validate that if there is matched id in the user table.

So I want to know how to implement this kind of validation?

© Stack Overflow or respective owner

Related posts about spring

Related posts about validation