开发者

spring mvc annotation validation

I have a form that looks like this

public class ValidationForm {
  private Person person;
 开发者_Go百科 @Size(min=1,max=10,message="out of range")
  private String test;
  //other stuff

My validation controller is like this

public void processForm(@Valid @ModelAttribute("validateForm") ValidationForm vform, 
  BindingResult result){

My Person class is like this

public class Person {
private String id;
@Size(min=1, max=35, message="Enter less than 35 Charercters")
private String firstName;
@Size(min=1, max=35, message="Enter less than 35 Charercters")
private String lastName;

if firstname or lastname is empty in my jsp page, there is no validation error. but if test is empty then there is a validation error. What should i do to validate properties of object in the form. Right now only properties of the form are getting validated.


I changed my validation form to

public class ValidationForm {
@Valid
private Person person;
@Size(min=1,max=10,message="out of range")
private String test;

and now it works

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜