Reputation: 1687
How can I obtain the same behavior as String.format(String, Object ...) in a JSP(x) page? Is there a tag library / function library yet available for this purpose? I need something that given a source string and a set of arguments performs the substitutions like
<ns:tag source="Hi {0} {1}" arguments="'name','surname'" />
or
${ns:func("Hi {0} {1}", "'name','surname'")}
that results in
Hi name surname
Thanks you for any suggestion, Stefano
Upvotes: 1
Views: 5111
Reputation: 692231
You're looking for the JSTL <fmt:message>
tag:
<fmt:message key="the.message.key">
<fmt:param value="name"/>
<fmt:param value="surname"/>
</fmt:message>
It uses java.text.MessageFormat
internally, though.
Most UI frameworks also have their own version of such a tag.
Upvotes: 1