Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring message in JSTL Tag

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'/>">
like image 335
zmanc Avatar asked Jul 30 '13 14:07

zmanc


People also ask

What is spring message tag?

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.

Does spring use JSTL?

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.

What is FMT message?

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.

What is spring boot Jstl?

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.


2 Answers

I think what you wanna do is.

<spring:message code='lman.ilr.closeItemDetail' var="closeMessage"/>

Then

<dsg:sidePanelContent closePanelText="${closeMessage}">
like image 157
Franz Joseph Avatar answered Oct 06 '22 12:10

Franz Joseph


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.

like image 40
JB Nizet Avatar answered Oct 06 '22 10:10

JB Nizet