I am using both JSTL (reference implementation of 1.2 spec) and struts 2.2.1 in my Web application, and I am noting incompatibilities in the way JSTL's fmt:message tag and corresponding Struts tags handle i18n. I have all i18n messages in MessageResources_<locale>.property files. Both JSTL fmt tags and struts tags use these resource bundles when formatting strings.
JSTL fmt:message behaviour is to put a string from the MessageResources_*.property through MessageFormat only if the fmt:message tag contains a fmt:param element. In that case the message from the bundle needs to follow MessageFormat syntax (e.g. treat apostrophe or single quote character as an escape character). Otherwise if fmt:message does not have a fmt:param it simply prints out non-modified message from the bundle to the JspWriter. This means that I need to escape special characters (like apostrophe and curly braces) ONLY if the message is parameterized. Implementation of struts tags and ActionSupport#getText methods on the other side always uses MessageFormat regardless of whether the message is parameterized or not, and I always have to escape MessageFormat special characters. To illustrate this here is an example: MessageResources.properties: test.message1 = How are you doin' friend? test.message2 = How are you doin'' friend? test.message3 = How are you doin' {0}? test.message4 = How are you doin'' {0}? and test.jsp: <strong>JSTL</strong><br> <fmt:message key="test.message1"/><br> <fmt:message key="test.message2"/><br> <fmt:message key="test.message3"><fmt:param>Joey</fmt:param></fmt:message><br> <fmt:message key="test.message4"><fmt:param>Joey</fmt:param></fmt:message><br> <br> <strong>Struts</strong><br> <s:text name="test.message1"></s:text><br> <s:text name="test.message2"></s:text><br> <s:text name="test.message3"><s:param>Joey</s:param></s:text><br> <s:text name="test.message4"><s:param>Joey</s:param></s:text><br> then this is what I would get on my page: JSTL How are you doin' friend? How are you doin'' friend? How are you doin {0}? How are you doin' Joey? Struts How are you doin friend? How are you doin' friend? How are you doin {0}? How are you doin' Joey? This makes it impossible to reuse the messages from both libraries (e.g. test.message1 from the example above). Is there a way to configure or customize Struts to treat i18n strings from resource bundles the same way JSTL treats them? Any help would be appreciated. Thanks Nenad