Here is my goal.
1.) user selects some excel files (checkbox)
2.) he selects x number of them.
3.) we get errors cause rules are violated.
4.) display errors only on the one that have bad values (say over 50.00).
do not show errors on other fields without it.
here is the jsp page.Code:@Override public void validate(Object obj, Errors err) { ExcelCommand excelCommand = (ExcelCommand) obj; if (excelCommand.getExcelModel() != null && excelCommand.getExcelLine().size() > 0) { int index = 0; for (ExcelModel excelModel : excelCommand.getExcelModel()) { if (excelModel.getValue() > 50.00) { err.rejectValue("excelModel["+index+"].value", "error.excel.toobig", new Object[] {excelModel.getValue() }, "excel value is too big"); } ++index; } } }
Here is my command objectCode:<c:forEach items="${excelFiles}" var="excelFile" varStatus="status"> <!-- start table row --> <td><form:checkbox path="excelModel[${status.index}].value" value="${excelFile.value}"/></td> <td> <div id="error"> <form:errors path="excelModel[${status.index}].value"/> </div> </td> <!-- end table row --> </c:forEach>
ExcelModel is pojo with excel name, excel value and excel size.Code:class ExcelCommand implements serializable { private static final long serialVersionUID = 31625646343423423L; private List<ExcelModel> excelModel; public List<ExcelModel> getExcelModel() { return excelModel; } public void setExcelModel(List<ExcelModel> excelModel) { this.excelModel = excelModel; } }
I put system.out.prinlnt right before the errors. It prints out but the error never gets render to the page.


Reply With Quote