You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "william edwards (JIRA)" <ji...@apache.org> on 2006/07/10 11:08:16 UTC
[jira] Created: (STR-2908) tiles display error/inconsistency
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
[jira] Commented: (STR-2908) tiles display error/inconsistency
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/struts/browse/STR-2908?page=comments#action_38909 ]
Niall Pemberton commented on STR-2908:
--------------------------------------
Can you not just specify a property of "value" on the <bean:message> tag?
<bean:message name="InfoHeader" property="value"/>
> tiles display error/inconsistency
> ---------------------------------
>
> Key: STR-2908
> URL: http://issues.apache.org/struts/browse/STR-2908
> Project: Struts 1
> Issue Type: Bug
> Components: Tiles
> Affects 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
[jira] Commented: (STR-2908) tiles display error/inconsistency
Posted by "Antonio Petrelli (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/struts/browse/STR-2908?page=comments#action_37696 ]
Antonio Petrelli commented on STR-2908:
---------------------------------------
Did you try to use:
<tiles:importAttribute name="InfoHeader"/>
What you described seems to be a bug, but it would be useful to check whether your code works with the code above, because <tiles:importAttribute> could behave differently if the "name" attribute is specified.
> 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
[jira] Commented: (STR-2908) tiles display error/inconsistency
Posted by "william edwards (JIRA)" <ji...@apache.org>.
[ http://issues.apache.org/struts/browse/STR-2908?page=comments#action_38626 ]
william edwards commented on STR-2908:
--------------------------------------
[[ Old comment, sent by email on Mon, 10 Jul 2006 12:15:59 +0200 ]]
Yes. I spent 4 hours trying every stragegy. Including the more specific
<tiles:importAttribute ..>
If I make the call
<tiles:useAttribute id="InfoHeaderId" name="InfoHeader"
classname="java.lang.String" />
I get a ClassCastException. It seems that Tiles sees type="string" and
then stuffs the value into an object called DirectStringAttribute. But
this class is not related to string.
I would suggest on the surface, it seems that far better flexibility and
robustness is introduced if the Object.toString() method is simply
called on the object being passed in.
Regards
William Edwards
> tiles display error/inconsistency
> ---------------------------------
>
> Key: STR-2908
> URL: http://issues.apache.org/struts/browse/STR-2908
> Project: Struts 1
> Issue Type: Bug
> Components: Tiles
> Affects 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