tiles display error/inconsistency
---------------------------------

         Key: STR-2908
         URL: http://issues.apache.org/struts/browse/STR-2908
     Project: Struts 1
        Type: Bug

  Components: Tiles  
    Versions: 1.2.8    
 Environment: JRE v1.4.2, JDK1.4.2_07
Ant v 1.6
    Reporter: william edwards
    Priority: Minor


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)) {
                 JspException e =
                     new JspException(messages.getMessage("message.property", 
key));
                TagUtils.getInstance().saveException(pageContext, e);
                 throw e;
             }
             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)  {
                 JspException e =
                     new JspException(messages.getMessage("message.property", 
key));
                TagUtils.getInstance().saveException(pageContext, e);
                 throw e;
           }

           key = value.toString();
        //end code change
        }

</snip>

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to