Results 1 to 3 of 3

Thread: MessageSource not being used during validation

Threaded View

  1. #1

    Default MessageSource not being used during validation

    I can't get my messages in messages.properties to be used during Spring validation of my form backing objects.

    app-config.xml:
    Code:
      <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="messages" />
      </bean>
    WEB-INF/classes/messages.properties:
    Code:
    NotEmpty=This field should not be empty.
    Form Backing Object:
    Code:
    ...
      @NotEmpty
      @Size(min=6, max=25)
      private String password;
    ...
    When I loop through all errors in the BindingResult and output the ObjectError's toString I get this:

    Field error in object 'settingsForm' on field 'password': rejected value []; codes [NotEmpty.settingsForm.password,NotEmpty.password,N otEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessage SourceResolvable: codes [settingsForm.password,password]; arguments []; default message [password]]; default message [may not be empty]

    As you can see the default message is "may not be empty" instead of my message "This field should not be empty".

    I do get my correct message if I inject the messageSource into a controller and output this:
    messageSource.getMessage("NotEmpty", new Object [] {"password"}, "default empty message", null);

    So why isn't Spring's validation using my messages.properties? I'm running Spring 3.1.1. Thanks!
    Last edited by neojonas; Jun 20th, 2012 at 04:10 PM.

Posting Permissions

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