spring message tag with multiple arguments

George Sun picture George Sun · Dec 21, 2011 · Viewed 54.5k times · Source

I am trying to get i18n message like below:

messageCode=Test message for {0} and {1} and {2}.

In jsp, I have this:

<spring:message code="messageCode" 
                arguments="${value1},${value2},${value3}" 
                htmlEscape="false"/>

The arguments:

value1=A,B
value2=C,D
value3=E,F

The output for what I want:

Test message for A,B and C,D and E,F 

The actual output:

Test message for A and B and C

Is there any way to overcome this? Thank you.

George

Answer

Ralph picture Ralph · Dec 21, 2011

The cause of the probelm is that , (comma) is the default separator. So at the end the spring message tag will get the String A,B,C,D,E,F for parameter arguments, and it will split this string into 6 different internal arguments for the message.

You must change the separator. If you use ; for example, then it will work.

<spring:message code="messageCode"
       arguments="${value1};${value2};${value3}"
       htmlEscape="false"
       argumentSeparator=";"/>

@See Spring Reference: Appendix F.6 The Message Tag