Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
1.2.8
-
None
-
None
-
JRE v1.4.2, JDK1.4.2_07
Ant v 1.6
Description
This problem occurs when I want to perform internationalisation, by feeding the keys from
ApplicationResources.properties into the tile.
1) I set the name attribute in my tiles definition file.Note: the key is "some.heading"
In my tiles def. file I do something like this.
<put name="InfoHeader" value="some.heading" type="string"/>
In my JSP I do:
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:importAttribute/>
<h1><bean:message name="InfoHeader"/></h1>
..
This gives me a servletexception.
[ServletException in:/layouts/BodyInfoLayout.jsp] Property for message key
must be a String' javax.servlet.ServletException: Property for message key
must be a String at
..
HOWEVER, if I do the following in my tiles definition file:
<put name="InfoHeader" value="some.heading" type="java.lang.String"/>
the above JSP works correctly. The problem is that it doesn't follow the
tiles config dtd The type is only supposed to be "string", "page" or "definition".
And this is seen as a warning by the SaXParser in the compilation of the tiles-defs.xml.
Fix problem and suggestion:
===========
(1) problem:
Having a look inside the code for the MessageTag class for the Bean tag
public int doStartTag() throws JspException {
String key = this.key;
if (key == null) {
// Look up the requested property value
Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
if (value != null && !(value instanceof String))
key = (String) value;
}
(2) Suggested solution
The value = "some.heading" turns out to be of type org.apache.struts.tiles.DirectStringAttribute, NOT java.lang.String , which causes
the code to go into the exception.
Why not write the code as:
public int doStartTag() throws JspException {
String key = this.key;
if (key == null) {
// Look up the requested property value
Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
//begin code change
if (value == null)
key = value.toString();
//end code change
}
</snip>