i am trying to persist an Entity using the sf:form.
this is the jsp:
<sf:form method="POST" action="${pageContext.request.contextPath}/addStudent" modelAttribute="student">
<fieldset>
<table>
<tr>
<th><sf:label path="nb">Number:</sf:label></th>
<td><sf:input type="text" path="nb"/><br/>
<sf:errors path="nb"></sf:errors>
</tr>
......
</table>
</fieldset>
the attribute in the entity is like that:
@NotNull(message="not null")
@Size(min=5, max=10, message="length min 5")
@Column(name="NB", unique=true)
private String nb;
the controller:
@RequestMapping(value="/addStudent", method=RequestMethod.POST)
public ModelAndView addStudent(HttpServletRequest request, @ModelAttribute("student") @Valid Student student, BindingResult bR){
ModelAndView mav = new ModelAndView("students");
if(bR.hasErrors()){
return mav;
}
studentService.saveStudent(student);
return mav;
}
Well, when i leave the nb field empty or the entry is to short i get a validation error. my problem is that the error is not shown in the jsp but an exception is thrown:
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='length min 5', propertyPath=nb, rootBeanClass=class i.have.serious.problem.Student, messageTemplate='length min 5'}
javax.validation.ConstraintViolationException: Validation failed for classes [i.have.serious.problem.Student] during persist time for groups [javax.validation.groups.Default, ]
maybe i miss something .. i appreciate any hint or help, thx
----------------------------- SOLVED -----------------------------------