-
1 Attachment(s)
Full example
hi, here is a example
1.- If you using Netbeans. Create a new message.properties on the folder other sources.
Attachment 4605
2.- open the file and set the key
title=MyTitleTest
3.- In your disparcher-servlet.xml (Spring IOC Container)
Code:
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
// this is you controller where you make the reference to the messageSource
<bean name="userProfileFirstLoginController" class="gaa.vaa.web.user.profile.UserProfileFirstLoginController">
<property name="messageSource" ref="messageSource" />
</bean>
2.- In this case in your controller implement MessageSourceAware
Code:
public class UserProfileFirstLoginController extends AbstractController implements MessageSourceAware{
private MessageSource messageSource_;
@Override
public void setMessageSource(MessageSource ms) {
messageSource_=ms;
}
protected ModelAndView handleRequestInternal(
HttpServletRequest request,
HttpServletResponse response) throws Exception {
Map<String,Object> model = new HashMap<String,Object>();
// here is how to get the message
String messageS = messageSource_.getMessage("title",null,Locale.ENGLISH);
model.put("messageS",messageS);
return new ModelAndView(modelAndView,model);
}
Done, you get the message