java - Spring MVC and JSR 303 -
i'm using spring 3 , jsr 303. have form backing object nested objects need validated. in example below, how validate formobject.getfoo().getbean()? when run code below, result parameter empty, if html page submits nothing, when validation should fail. note works(i.e. validation fails) when validate manually calling validate(formobject.getfoo().getbean(), bean.class)
.
@controller public class formcontroller { @requestmapping(method = requestmethod.post) public void process(httpservletrequest request, @valid formobject formobject, bindingresult result) { ... } // class needs validated. public class bean { @notblank private string name; } public class foo { private bean bean; } public class formobject { private foo foo; } }
if want validation cascade down child object, must put @valid annotation on field in parent object:
public class bean { @notblank private string name; } public class foo { @valid private bean bean; } public class formobject { @valid private foo foo; }
Comments
Post a Comment