You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Jamie Cockrill <ja...@gmail.com> on 2010/06/14 14:03:40 UTC
ViewPreparers and InsertAttributeTag
Dear All,
I fear I may have been a bit hasty and created a JIRA issue against
this already, for which I'm sorry. Retrospectively I thought it might
have been better to get in touch with the mailing list first. Firstly,
I am working with Tiles 2.2.1 and I am adding attributes to the
AttributeContext with a ViewPreparer as per the example at:
http://tiles.apache.org/framework/tutorial/advanced/preparer.html
The line of interest is:
attributeContext.putAttribute(
"my.attribute.name",
new Attribute("This is the value added by the ViewPreparer"));
I am then attempting to access the attribute in the JSP, using the
tiles:insertAttribute tag like so:
<tiles:insertAttribute value="${some EL which returns
'my.attribute.name'}" flush="true" />
When I attempt to render the page, I receive a stack trace with the
following root cause:
java.lang.ClassCastException: java.lang.String cannot be cast to
org.apache.tiles.Attribute
org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:306)
The full stack itself is rather hard to retrieve as the system is on a
separate network. A simple test-case would be to create a simple
project with Tiles 2.2.1, a ViewPreparer that inserts an attribute
with a String value (as above) and a JSP that tries to insert that
attribute.
The offending line of code seems to be the call to model.start in the
doTag, where the 'value' member is cast to an Attribute. It seems that
there doesn't appear to be any attempt to resolve the 'value' member
against the attribute-names in the attribute context.
Strangely, if I use "<tiles:useAttribute id="temp" name="${same EL as
above}" /> ${temp}" i get the content of the variable just fine.
I think the issue is either to do with the code being broken
(erroneous cast?) or the example being incorrect.
Thanks and apologies for the JIRA,
Jamie
Re: ViewPreparers and InsertAttributeTag
Posted by Jamie Cockrill <ja...@gmail.com>.
Antonio,
Many thanks for your help, that seems to have largely done the trick.
The JIRA is at: https://issues.apache.org/jira/browse/TILES-511
Jamie
On 14 June 2010 13:12, Antonio Petrelli <an...@gmail.com> wrote:
> 2010/6/14 Jamie Cockrill <ja...@gmail.com>:
>> attributeContext.putAttribute(
>> "my.attribute.name",
>> new Attribute("This is the value added by the ViewPreparer"));
>>...
>> <tiles:insertAttribute value="${some EL which returns
>> 'my.attribute.name'}" flush="true" />
>>
>> When I attempt to render the page, I receive a stack trace with the
>> following root cause:
>>
>> java.lang.ClassCastException: java.lang.String cannot be cast to
>> org.apache.tiles.Attribute
>
> From the docs:
>
> http://tiles.apache.org/framework/tiles-jsp/tlddoc/tiles/insertAttribute.html
> name: Name of the attribute to insert. This attribute will be ignored
> if the value attribute is specified.
> value: Attribute object to render directly. If it specified, the name
> attribute will be ignored.
>
> Thus, use "name".
>
> Antonio
>
> P.S. Where's the JIRA issue?
>
Re: ViewPreparers and InsertAttributeTag
Posted by Antonio Petrelli <an...@gmail.com>.
2010/6/14 Jamie Cockrill <ja...@gmail.com>:
> attributeContext.putAttribute(
> "my.attribute.name",
> new Attribute("This is the value added by the ViewPreparer"));
>...
> <tiles:insertAttribute value="${some EL which returns
> 'my.attribute.name'}" flush="true" />
>
> When I attempt to render the page, I receive a stack trace with the
> following root cause:
>
> java.lang.ClassCastException: java.lang.String cannot be cast to
> org.apache.tiles.Attribute
>From the docs:
http://tiles.apache.org/framework/tiles-jsp/tlddoc/tiles/insertAttribute.html
name: Name of the attribute to insert. This attribute will be ignored
if the value attribute is specified.
value: Attribute object to render directly. If it specified, the name
attribute will be ignored.
Thus, use "name".
Antonio
P.S. Where's the JIRA issue?