15

How can I format the arguments of my <spring:message>?

I have a message like this:

 message.myMessage=this is {0} my message {1} with {2} multiple arguments

My jsp has the following:

<spring:message code="message.myMessage" 
                arguments="<fmt:formatNumber value='${value1}' currencySymbol='$' type='currency'/>,${value2},${value3}" 
                htmlEscape="false"/>

which doesn't display value1, which is a number I would like formatted.

I am not sure I can add the fmt tag inside the argument list.

skaffman
  • 398,947
  • 96
  • 818
  • 769
blong824
  • 3,920
  • 14
  • 54
  • 75

2 Answers2

22

The arguments attribute of <spring:message> can contain JSP EL expressions, but not JSP tags.

Try un-nesting it. You can assign the result of <fmt:formatNumber> to a variable, e.g.

<fmt:formatNumber var="formattedValue1" value='${value1}' currencySymbol='$' type='currency'/>
<spring:message code="message.myMessage" arguments="${formattedValue1},${value2},${value3}" htmlEscape="false"/>
skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 5
    Awesome! Thank you so much. FYI I needed to change the argumentSeperator to '|' because a formatted currency has commas and will seperate the numbers once formatted. Thanks again – blong824 Jul 01 '11 at 17:24
1

Assign the formatted number to a variable then use it in your spring message tag :

<fmt:formatNumber value="${value1}"
                    var="value4"
                   type="currency"/>

<spring:message code="message.myMessage"
           arguments="${value4},${value2},${value3}"
          htmlEscape="false"/>
McDowell
  • 107,573
  • 31
  • 204
  • 267
Salim Hamidi
  • 20,731
  • 1
  • 26
  • 31