Announcement Announcement Module
Collapse
No announcement yet.
ValidationUtils.rejectIfEmptyOrWhitespace() - errorCode parameter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ValidationUtils.rejectIfEmptyOrWhitespace() - errorCode parameter

    Hello,

    First posting...

    Inside my Validator's validate() method I have a line like the following:

    Code:
    ValidationUtils.rejectIfEmptyOrWhitespace(errors,"username","requiredField","Required field");
    The docs say that errorCode (what I'm passing as "requiredField") is interpretable as a message key.

    I have a .properties file with the message in. How do I link this up with Spring to get that one displayed?

    Thanks,

    PUK

  • #2
    The easiest way is with a jsp tag looking something like:

    Code:
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    
    ...
    
    <form:form>
    First Name: <form:input path="username" /> <form:errors path="username" />
      </form:form>
    
    ...
    HTH

    Comment


    • #3
      Originally posted by jpreston View Post
      The easiest way is with a jsp tag looking something like:

      Code:
      <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
      
      ...
      
      <form:form>
      First Name: <form:input path="username" /> <form:errors path="username" />
        </form:form>
      
      ...
      HTH
      Thanks for the reply. I already have that and it's rendering the defaultMessage I provide to rejectIfEmptyOrWhitespace(). The text "Required Field" is coming out. I was hoping to get it to lookup in a resource bundle.

      I guess I don't understand the purpose of the errorCode parameter? Anyone?

      I could just lookup the text from the resource bundle in the Java validation code and use that as the defaultMessage but I wonder if I'm missing a trick?

      Thanks,

      PUK

      Comment


      • #4
        You need to define a messageSource. See http://static.springsource.org/sprin...-messagesource

        Comment

        Working...
        X