Announcement Announcement Module
Collapse
No announcement yet.
form:errors won't show errors. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • form:errors won't show errors.

    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.

    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 the jsp page.
    Code:
    <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>
    Here is my command object


    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;
    	}
    }
    ExcelModel is pojo with excel name, excel value and excel size.

    I put system.out.prinlnt right before the errors. It prints out but the error never gets render to the page.

  • #2
    i search for how to do this and appearntly spring doesn't have easy to support such a common task

    Comment


    • #3
      bump for any additional help.

      Comment

      Working...
      X