Tuesday, 15 June 2010

validation - can @Valid annotation check on fields recursively in spring mvc? -



validation - can @Valid annotation check on fields recursively in spring mvc? -

i create model object jsr-303 validator annotation:

public class userinfobasicmodel implements serializable{ @notnull(message="cannot null") @notempty(message="cannot empty") private string name; //getter , setter //..ignored.. }

auto data-binding in controller:

@controller @requestmapping("/user") public class usercontroller { @requestmapping(method = requestmethod.post, value = "/registry/") public string registry(httpservletrequest request, modelmap modelmap, @valid userinfobasicmodel userinfobasicmodel, bindingresult result) { //...some code here... } }

in above scenario, works fine validation. when encapsulate model object below, validation on userinfobasicmodel doesn't work anymore:

the object encapsulates userinfobasicmodel object:

public static class userupdateformtransmitter { @valid private userinfobasicmodel userinfobasicmodel; //getter , setter //..ignored.. }

the controller:

@controller @requestmapping("/user") public class usercontroller { @requestmapping(method = requestmethod.post, value = "/registry/") public string registry(httpservletrequest request, modelmap modelmap, @valid userupdateformtransmitter userupdateformtransmitter, bindingresult result) { //...some code here... } }

i'm wondering why doesn't @valid annotaion works recursively jsr 303: bean validation says.could 1 give me solution can valid object recursively, lot!!!!

i have never done recursive validation, according this possible purchase tagging sub-objects @valid.

validation spring-mvc bean-validation hibernate-validator

No comments:

Post a Comment