views:

32

answers:

1

I have a form that looks like this

public class ValidationForm {
  private Person person;
  @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.

+2  A: 

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