JSP: Problem Using Spring Message with JSTL

Couple of days back I was trying to externalize the labels and messages in a JSP file to a property file. As I was using Spring MVC, decided to use <spring:message> tag to achieve this. Everything else worked fine except when I used <spring:message> tag as a value attribute of <c:set>. Albeit it sounds very simple, I had to spend some time finding out the way. And hence considering this a candidate for my blog.

Problem:

Unable to use <spring:message> tag with the JSTL  <c:set> tag like below:

<c:set var=”someVar” value=”<spring:message code=’some.value’/>” />

Solution:
Nest the <spring:message> tag in the JSTL tag.

<c:set var=”someVar”>
<spring:message code=”some.value”/>
</c:set>

Enjoy Learning,
Kamlesh

Advertisements

5 thoughts on “JSP: Problem Using Spring Message with JSTL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s