Announcement Announcement Module
Collapse
No announcement yet.
ValidationUtils not finding error msgs in properties file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment

    Working...
    X