There is a grid which has multiple rows. Each row has the two same text fields. I am using JSR 303 to validate these fields and the validation is happening alright. However the issue is that multiple error messages are being shown(one for each row) which is not desirable. Is there a way to display only one error message per field for all the rows?
public ModelAndView insert(@Valid @ModelAttribute("proposalwiseselectionform")ProposalWiseSelectionForm proposalwiseselectionformobj,
BindingResult result,
HttpServletRequest request, HttpServletResponse response) {
if (result.hasErrors()) {
if (formBeanObj == null) {
formBeanObj = proposalwiseselectionformobj;
}
mav = new ModelAndView("proposalwiseselection");
mav.addObject("proposalwiseselectionform", formBeanObj);
}
}
public class ProposalWiseSelectionForm {
private String txtLineOfBusiness;
private String txtProduct;
private String btn;
private String clickedGo="N";
private List arrLineOfBusiness=new ArrayList();
private List arrProduct=new ArrayList();
@Valid
private ArrayList documentList=initiateDocumentList();
private String txtPageMode="I";
private String enableDiscardBtn="N";
private String enableInsertBtn="N";
public ArrayList initiateDocumentList(){
ArrayList arr=new ArrayList();
for(int i=0; i<1;i++){
arr.add(new ProposalWiseSelectionChildForm(i));
}
return arr;
}
}
public class ProposalWiseSelectionChildForm {
private String numProposalWiseSelection;
private String txtTransactionType;
private String txtTransactionTypeCode;
@NotEmpty(message="Transaction Type cannot be empty")
private String txtTransactionDesc;
@NotEmpty(message="Document Type cannot be empty")
private String txtPolicyDocument;
private String ynChkBox="0";
}
JSP snippets are as follows,
form:form action="/proposalwiseselection" commandName="proposalwiseselectionform" method="POST" id="proposalwiseselection"/
form:errors path="*" cssClass="errorblock" element="div"/
form:input path="documentList[${docStatus.index}].txtTransactionDesc" cssClass="noneditableinputbox" size="40" onkeydown="transactionTypeLOV(event.keyCode,this)" readonly="true" title="Press F2 to get transaction type list" /
form:hidden path="documentList[${docStatus.index}].txtTransactionTypeCode"/
form:input path="documentList[${docStatus.index}].txtPolicyDocument" cssClass="noneditableinputbox" size="40" readonly="true"/
form:hidden path="documentList[${docStatus.index}].numPolicyDocumentCode"/