Programmer's Cookbook

Recipes for the practical programmer

Friday, June 27, 2008

 

Spring + ResourceBundleMessageSource + Arguments

Recently I had a request to move some hard-coded error messages from the source files to an external properties file. At first I ran into some issues since we were using parameters, but spring's taglib allows for that so here goes:

Spring config

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="com.harryfwong.shared.messages">
</property>


com/harryfwong/shared/messages.properties

error.testingParameters=Are you passing in Parameters: {0}, {1}?


displayError.jsp

<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<spring:message code="error.testParameters" argumentseparator=";" arguments="param1;param2">
</spring:message>

Labels: , , , , ,


Comments:
thanks!!!
 
Tx alot
 
Great one nice and simple..just a minor thing, property name in "messages.properties" should be consistent with the one specified in the JSP..either rename "testParameters" to "testingParameters" or vice versa

Cheers
 
thanks helped me, though I used
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?