I can't get my messages in messages.properties to be used during Spring validation of my form backing objects.
app-config.xml:
WEB-INF/classes/messages.properties:Code:<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messages" /> </bean>
Form Backing Object:Code:NotEmpty=This field should not be empty.
When I loop through all errors in the BindingResult and output the ObjectError's toString I get this:Code:... @NotEmpty @Size(min=6, max=25) private String password; ...
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!


Reply With Quote