Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSTL Message Bundle with Localized Parameter in Placeholder

I'm using Spring and JSTL.

I have the following keys in a bundle (messages.properties):

key.withplaceholder= Never {0}.
key.giveup=give up

And I have the following code:

<fmt:message key="key.withplaceholder">
  <fmt:param value="lie"/>
</fmt:message>

With this code I can show the message:

Never lie.

But if I want to use the key.giveup to show "Never give up" I don't know how to do it. How can I accomplish this?

Finally, is there a better way to do it? (without having to load a resource bundle in the jsp).

like image 986
Christian Vielma Avatar asked Mar 20 '13 18:03

Christian Vielma


People also ask

What is the use of the parameter placeholder in the resource bundle?

The is used in scenarios where the localized messages are to be personalized or the value to be displayed is dynamic. We can have many parameter placeholders in the resource bundle starting with index 0, we can supply the arguments using tag.

How to use <FMT:message> tag in JSTL format?

In this post, you will learn how to use the <fmt:message> tag in the JSTL format tags library with code example. The <fmt:message> is used to display the localized messages by replacing the key specified, with the actual message loaded from the resource bundle.

What is JSTL in JSP?

The JSP Standard Tag Library (JSTL) represents a set of tags to simplify the JSP development. Fast Development JSTL provides many tags that simplify the JSP. Code Reusability We can use the JSTL tags on various pages.

How many types of tags are there in JSTL?

There JSTL mainly provides five types of tags: Tag Name Description Core tags The JSTL core tag provide variable suppo ... Function tags The functions tags provide support for s ... Formatting tags The Formatting tags provide support for ... XML tags The XML tags provide flow control, trans ... 1 more rows ...


1 Answers

You can use the var attribute to store the formatted message in a page scoped variable instead of printing it out to the response.

<fmt:message key="key.giveup" var="key" />
<fmt:message key="key.withplaceholder">
    <fmt:param value="${key}" />
</fmt:message>
like image 92
BalusC Avatar answered Sep 21 '22 01:09

BalusC