According to this post from 3 years ago the only way to display a spring message in a jstl tag is to wrap it in a <c:set var="someVar">
which does "work" but it seems very far from ideal.
Fast forward 3 years, is this still the only way to handle this?
Here is my code
Works, but not "ideal"
<c:set var="closeMessage">
<spring:message code='lman.ilr.closeItemDetail'/>
</c:set>
<dsg:sidePanelContent closePanelText="${closeMessage}">
Doesn't work, returns a string of <spring:message code='lman.ilr.closeItemDetail'/>
<dsg:sidePanelContent closePanelText="<spring:message code='lman.ilr.closeItemDetail'/>">
The spring:message tag provides you with internationalization support using Spring's MessageSource concept. The MessageSource is an interface providing functionality for retrieving messages. It closely resembles JSTL's fmt:message -tag, however, the MessageSource classes can be integrated with the Spring context.
Spring provides a couple of out-of-the-box solutions for JSP and JSTL views. Using JSP or JSTL is done using a normal view resolver defined in the WebApplicationContext . Furthermore, of course you need to write some JSPs that will actually render the view.
The <fmt:message> tag is used for displaying an internationalized message. It maps the key of localized message to return the value using a resource bundle specified in the bundle attribute.
JavaServer Pages Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. Here we will be discussing how to use the Maven build tool to add JSTL support to a Spring MVC application.
I think what you wanna do is.
<spring:message code='lman.ilr.closeItemDetail' var="closeMessage"/>
Then
<dsg:sidePanelContent closePanelText="${closeMessage}">
The spring message tag, just as fmt:message
, has a var attribute that can be used to store the message instead of displaying it.
It always helps to read the documentation.
Also, your wrong message probably comes from forgettin to declare the spring taglib at the top of your JSP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With