Announcement Announcement Module
Collapse
No announcement yet.
onSubmit() doesn't show errors (Spring MVC 2.0) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • onSubmit() doesn't show errors (Spring MVC 2.0)

    In Spring MVC 2.0-RC4, when I've passed the validation checks but encounter an error condition (a Db/logic error, not a field validation error) in onSubmit(), I set the errors/BindException object and return:

    Code:
    protected ModelAndView onSubmit(HttpServletRequest httpServletRequest,
                                    HttpServletResponse httpServletResponse,
                                    Object command,
                                    BindException errors) throws Exception {
    
    BizObject bizObject = (BizObject) command;
    ...
        if (someDbCheckFails) {
            ModelAndView mav = new ModelAndView(getFormView(), "bizObject", bizObject);
            errors.reject("db.error.condition");
            mav.addObject("errors", errors);
            return mav;
        }
    ...
    The form view is returned but there are no error messages printed on the page. I have this snippet on the .jsp to print error messages:

    Code:
      <spring:bind path="bizObject.*">
          <c:if test="${not empty status.errorMessages}">
              <div class="error">
                  <c:forEach var="error" items="${status.errorMessage}">
                      <c:out value="${error}" escapeXml="false"/><br/>
                  </c:forEach>
              </div>
          </c:if>
      </spring:bind>
    There is no exception or stack trace. Any idea why the errors are not printing? There are no specific examples of this in any of the four books I've read on Spring; they only cover the simplest field-related validation errors. (TIA!)
    Last edited by psconnolly; Oct 4th, 2006, 11:36 PM.

  • #2
    try status.errorMessages this is what we use.

    Also setting the errors object as you do I don't know if that works. I believe the way you do it, the current model is being overwritten by your new object.

    You might try the following

    Code:
    BizObject bizObject = (BizObject) command;
    
        if (someDbCheckFails) {
            errors.reject("db.error.condition");
            Map model = errors.getModel();
            model.put("bizObject", bizObject);
            return new ModelAndView(getFormView(), model);
        }
    Last edited by Marten Deinum; Oct 5th, 2006, 04:05 AM.

    Comment


    • #3
      Thanks! That change works. (It would be nice if RJohnson et. al. would include examples of this type of error handling in their documentation! Life does not begin and end with validation errors. )

      Comment


      • #4
        I believe the do use this in one of their sample applications. Not sure which one, but I saw it somewhere. Will try to see if I can find the source. Might come in handy..

        Comment

        Working...
        X