我想使用多个ModelAttribute,所以我创建了一个包装器对象,它包含每个ModelAttribute的实例,但是当我尝试使用自己的验证器验证“infoFormation”和“Formation”对象时,BindingResult对象是指LicenceForm对象,因此无法从其上的其他2个对象中找到任何错误的字段。
(我没有使用自定义验证只是注释)
类
public class LicenceForm {
@Valid
private Formation licenceformation = new Formation();
@Valid
private InfoFormation infoformation = new InfoFormation ();
// getters ad setters..
}
CONTROLLER
@RequestMapping(value="/ajoutLicence")
public String ajoutLicence(@Valid LicenceForm LF,BindingResult Result,
Model model) throws IOException{
if(Result.hasErrors()){
return "candidat/depotDossier/ajout_licence";
}
PAGE JSP
<f:form method="post" action="ajoutLicence" modelAttribute="LicenceForm">
<f:input path="licenceformation.intituleLicence"/>
<f:errors path="licenceformation.intituleLicence" cssClass="error"></f:errors>
<f:label path="infoformation.mentionFormation" />
<f:errors path="infoformation.mentionFormation" cssClass="error"></f:errors>
....
</f:form>