Results 1 to 2 of 2

Thread: ValidationUtils not finding error msgs in properties file

  1. #1
    Join Date
    Jan 2006
    Posts
    2

    Default ValidationUtils not finding error msgs in properties file

    I'm building a simple web app that uses Spring MVC and validation. I want an error message to be displayed from a properties file if validations for fields fail. However for some reason Spring is not finding my properties file error messages. It is, however, displaying the default error message in my validator code.

    Here is the relevant code:

    public RegisterStudentController extends SimpleFormController
    {
    // wired to use the StudentValidator class
    }

    messages.properties:
    (placed in WEB-INF/classes directory to be in classpath).
    required.phone=Phone Number Required <<--- ERROR MSG I WANT!

    StudentValidator.java:
    public void validate (Object command, Errors errors)
    {
    ValidationUtils.rejectIfEmpty(errors,
    "phoneNumber",
    "required.phone",
    null,
    "Enter a Phone Number");
    }

    studentRegistration.jsp:
    <spring:bind path="student.phoneNumber">
    <td>Phone Number</td>
    <td><input type="text" name="phoneNumber"></td>
    <td>
    <font color="red"><c:out value="${status.errorMessage}"/></font>
    </td>
    </spring:bind>

    The problem is that I get the default error Message "Enter a Phone Number" instead of the message from the properties file "Phone Number Required".

    Any ideas on why Spring is not finding my properties file? Do I have to configure the location of the properties file for Spring somewhere?

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Posts
    2

    Default Solution

    Never mind, I found the problem. The following has to be in the spring config file:

    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
    <property name="basename"><value>messages</value></property>
    </bean>

Posting Permissions

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