Thursday, January 17, 2008

spring mvc MessageSource

A MessageSource is sourced by a number of "message bundles" which provide the mapping from a key to a readable String. The code below points out a sample message source:

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

This code creates a bean for a reloadable message source, so when changes are made, they will be picked up without redeployment or reloading. The basename represents where the messages can be found, and in this case the default file will be in the folder '/WEB-INF/messages' in a file called 'validation.properties'. To support internationalisation, multiple message bundles (i.e. validation_XX_YY.properties) can be created in this folder using the correct naming convention for the languages required.

Now if a message of code, for example, 'empty.value' requires a message it will look for the message within these files/this file, using the standard property convention 'key=value'.

Labels:

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home