Results 1 to 3 of 3

Thread: form:errors won't show errors.

  1. #1
    Join Date
    Feb 2007
    Posts
    291

    Default 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. #2
    Join Date
    Feb 2007
    Posts
    291

    Default

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

  3. #3
    Join Date
    Feb 2007
    Posts
    291

    Default

    bump for any additional help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •