Hi all I am getting the following error whenever I am trying to invoke validator in my spring
Servlet.service() for servlet spring threw exception: java.lang.IllegalStateException: Invalid target for Validator
Please have a look and help me out in this error, previously I user the validation for login page and it is working fine but now its not working.
Here is my code snippet .
Controller
@Controller
public class NewUserRegistration
{
@Autowired
private UserService userService;
@Autowired
private NewUserValidator newUserValidator;
@InitBinder
public void initBinder(WebDataBinder binder)
{
binder.setValidator(newUserValidator);
}
@RequestMapping(value="/newUserAdd", method=RequestMethod.POST)
public String addUser(@ModelAttribute("user")@Valid User user,BindingResult result, Model model)
{
return "NewUser";
}
}
Validator
@Component
public class NewUserValidator implements Validator
{
@Override
public boolean supports(Class<?> classz)
{
return NewUserRegistration.class.equals(classz);
}
@Override
public void validate(Object obj, Errors error)
{
//Validation login for fields
}
}
JSP Page
<form:form action="newUserAdd" method="POST" modelAttribute="user">
<center>
<table>
<tr><td>User Id:</td><td><input name="userId" type="text" /></td><td><font color="red"><c:out value="${userIdError}" /></font> </td></tr>
<tr><td>Password:</td><td><input name="userPassword" type="password"/></td><td><font color="red"><c:out value="${userPasswordError}" /></font></td></tr>
<tr><td>Confirm Password:</td><td><input name="userConfirmPassword" type="password"/></td><td><font color="red"><c:out value="${userPasswordError}" /></font></td></tr>
<tr><td>Name:</td><td><input name="userName" type="text"/></td><td><font color="red"><c:out value="${userPasswordError}" /></font></td></tr>
<tr><td></td><td><input type="submit" value="Create"/></td></tr>
</table>
</center>
</form:form>
http://stackoverflow.com/questions/4715860/why-is-my-spring-3-validator-validating-everything-on-the-model
– Justificationhttp://stackoverflow.com/questions/14533488/addiing-multiple-validators-using-initbinder
– JustificationNewUserRegistration
classes and you try to validate aUser
object. Different types, hence not compatible, hence the error. – Alumnus