简体   繁体   中英

Stripes error not appearing on text field in form

I have a phone number component that I am trying to validate, but for some reason, I am unable to get the stripes validation error to show up on the phone number field on the form. If I display the tag outside of the form, the errors display, but they are not attached to the field.

<e:declare-component name="PhoneNumberForm" css="true" js="true">
  <stripes:errors /> <%-- This tag displays errors --%>
    <e:sslform id="submit-phone-number-form" action="${componentContext.action}">
      <div class="phone-wrapper">
        <stripes:text name="phoneNumber" id="phoneNumber" class="TextInput" />
        <stripes:errors field="phoneNumber" /> <%-- This tag DOES NOT display errors --%>
      </div>
      ...
    </e:sslform>
</e:declare-component>

The form submits to a java class that extends ActionBean and implements the ValidationErrorHandler. I see that the validation methods are being called, and ValidationErrors is not empty (it contains the phone number validation error.)

Something to note: When I change the form to submit to a beanclass instead of an action, the errors fields are displayed correctly; however, this is not a solution for me since this component is used elsewhere in the code base. What is different between beanclass and action?

Any ideas as to why? Thanks!

When a stripes:error tag is nested inside a stripes:form tag, the errors displayed will only be those resulting from posting the form. Conversely one could say since there is no containing stripes:form it is unclear from what action the phone number validation error results.

You could try supplying an action attribute to the stripes:errors tag:

<stripes:errors field="phoneNumber" action="${componentContext.action}"/>

Just to tell Stripes from which form action the error message must result.

I have never tried this myself, but it's worth a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM