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
 
A very informative and engaging post. The key points have been explained nicely.workday hr training
 
Good points explained in a very simple way. Thanks for sharing.boomi training courses

 
Explore comprehensive Workday Studio Courses designed to help learners understand integration development and Workday system connectivity. The training supports skill development in areas such as data transformation, integration configuration, and enterprise workflows.
 
Post a Comment



<< Home

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