Announcement Announcement Module
Collapse
No announcement yet.
How do I check if there were validation errors? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I check if there were validation errors?

    I am using the SimpleFormController to display a form, but I need more control over what HTML to show when there are errors then I can achieve simply using the form:errors tag.

    For example, here is an example onBindAndValidate method
    Code:
    @Override
    protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception {
        errors.reject("credentials.invalid", "The supplied credentials were invalid");
    }
    In my JSP, what I really want to do is something like this:

    Code:
    <c:if test="not empty ${errors}">
    ...
    </c:if>
    But I can't seem to find a straightforward way to do that! The "errors" variable is only available from within the <spring:hasBindErrors> tag, which means I could do this:

    Code:
    <spring:hasBindErrors name="command">
        <c:if test="not empty ${errors}">
        ...
        </c:if>
    </spring:hasBindErrors>
    but that seems a little cumbersome... Is this the recommended way??

  • #2
    Why do you think that is cumbersome?

    Comment


    • #3
      <springtag:hasBindErrors name="command">
      <form:errors path="*"/>
      </springtag:hasBindErrors>

      how short or neat or straightforward do you want

      OR do this next to form element
      <form:errors path="your_form_element"/>

      Comment

      Working...
      X