Spring message tag | Argument Separator

Today, I worked on a Spring application. I had to change some small frontend things. One of them was to create a label containing a price. To follow the internationalization (I18N) concept I used the Spring message tag.

The text I had to insert had some variables, which should be inserted during the runtime. I marked them in square brackets:

 Ja, ich möchte mein [deviceType] für nur [price] im Monat absichern.

// The output looks like
Ja, ich möchte mein Fernseher für nur 9,95 € im Monat absichern. 

As you can see the price is separated by a comma in Germany. I used the spring message tag, but the outcome wasn’t as expected:

<spring:message code="text.test"
  arguments="${deviceType},${price}" />

// output | Where are the 0,95 cents are gone?
Ja, ich möchte mein Fernseher für nur 9 € im Monat absichern. 

The spring message method uses comma as a default. Therefore the cents are cut off. They would be used for the next argument if there would be one.

To change the separator from comma to something else, the Spring developers added an argumentSeparator attribute. By adding this attribute the output looks as expected.

<spring:message code="text.test"
  arguments="${deviceType};${price}" argumentSeparator=";" />
// output
Ja, ich möchte mein Fernseher für nur 9,95 € im Monat absichern. 

Let a comment and check out my other articles.

chevron_left
chevron_right

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website

This site uses Akismet to reduce spam. Learn how your comment data is processed.