[opencms-dev] Strange behaviour when using localized string <fmt:message> with digits in key attribute

Thomas Adamek adamek at webtrio.de
Tue Mar 18 15:58:37 CET 2008


Hi,

I noticed a problem using the <fmt:message> tag from JSTL in an OpenCms
7.0.4 module/project to display language dependent text in templates and
page elements. This should be used to display language-depend text for
selections made in a SelectorWidget out of a XML content.

I have created a module, let's say it's named com.test.module and placed
several messages_xx.properties files in the classes/com.test.module/
directory with some simple content:

messages_de.properties (for German localization)
====

text.test.title = Das ist ein Test
text.icon1.title = Icon Nummer eins
text.icon_1.title = Icon Nummer eins
text.icon.1.title = Icon Nummer eins

====

messages_en.properties
====

text.test.title = This is a test
text.icon1.title = Icon number one
text.icon_1.title = Icon number one
text.icon.1.title = Icon number one

====

The JSP looks the following:

====

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="locale">en</c:set>
<fmt:setLocale value="${locale}"/>
<fmt:setBundle basename="com.test.module.messages" scope="page" />
<html>
  <head>
      <title><fmt:message key="text.test.title" /></title>
  </head>

  <fmt:message key="text.test.title" />
  <fmt:message key="text.icon1.title" />
  <fmt:message key="text.icon_1.title" />
  <fmt:message key="text.icon.1.title" />
  </body>
</html>

===

I get the HTML output:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
      <title>This is a test</title>
  </head>
  This is a test
  ???text.icon1.title???
  ???text.icon_1.title???
  ???text.icon.1.title???
  </body>
</html>

==

The first element text.test.title is displayed without any doubt but none of
the text elements which contain digits at any place in the key name is
shown. Omitting the OpenCms tag lib (second line, first taglib include) does
not solve the problem.

This problem occurs inside OpenCms only, when I try the same code outside of
OpenCms (e.g. in a Tomcat web application - of course omitting the first
taglib include for <cms:> tags and putting the messages files into the
WEB-INF/classes directory), this works without any problem, all texts are
displayed in this case.

It is important for me to use numbers in the text key name to allow to
display alternative text as indexed value from a select widget of a
structured XML content where the user selects options from a list.

I would appreciate any idea or suggestion.

Thanks a lot
Thomas




More information about the opencms-dev mailing list