0

I tried to add model attribute in controller which is causing Validator to throw exception.

java.lang.IllegalStateException: Invalid target for Validator

@ModelAttribute("summary")
public Summary createStudent(Student student) {
    return saveService.saveStudent(student);
}

If @ModelAttribute("summary") is removed it works perfectly but not able to access the data in view.

If @ModelAttribute("summary") is enabled it throws above exception.

Validator

public class StudentValidator implements Validator {

    public StudentValidator() {
    }

    public boolean supports(Class<?> paramClass) {
        return Student.class.equals(paramClass);
    }

    public void validate(Object object, Errors errors) {

        Student sutdent = (Student) object;

        // Validation here for student 

    }
}

Already Refered Invalid target for Validator in spring error?

What is wrong?

I don't see any problem with my validator.

Thanks.

Community
  • 1
  • 1
Jose
  • 59
  • 3
  • 12

0 Answers0