3

I have validator class which uses

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages" />
</bean>

Besides validator which does more complex validation I also use JSR303 like

@NotNull(message="null value is not allowed")
 protected String postCode;

I want for JSR to use same file source messages.

  @NotNull(message=<SOMEHOW GO TO MY messages_en_US.properties AND EXTRACT SOMETHING LIKE : user.poscode.null>)

Thanks!

Aubergine
  • 5,862
  • 19
  • 66
  • 110
  • Have a look at [this question](http://stackoverflow.com/questions/6246381/getting-localized-message-from-resourcebundle-via-annotations-in-spring-framewor) - it appears to have a solution. –  Nov 18 '11 at 09:15
  • 1
    that doesn't help, I am really bad at evaluating answers based on similar, but not same topics :-( – Aubergine Nov 20 '11 at 09:09

2 Answers2

3

By default JSR303 validator looks for a file called ValidationMessages.properties, which is bundled with the implementation you use. If you want to add your own constraint validation messages you have to provide your own ValidationMessages.properties, and add to it the message.

You can look at Message interpolation, Hibernate validator docs.

But what I've just describe its Java EE standard behaviour I don't know if Spring behaves in the same way

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
landal79
  • 1,520
  • 1
  • 11
  • 26
0

I resolved the situation with help of another more focused question of mine on simillar topic. Anyone interested : javax.validation how to target different locale?

Please be aware however that there will be a need in two sets of files including resourcebundle and properties.

Community
  • 1
  • 1
Aubergine
  • 5,862
  • 19
  • 66
  • 110