Uploaded image for project: 'Tiles'
  1. Tiles
  2. TILES-511

InsertAttributeTag throws ClassCastException on attribute added through ViewPreparer

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.2.1
    • None
    • None
    • Tomcat 6.0.24 on Ubuntu

    Description

      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="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="my.attribute.name" /> ${temp}" i get the content of the variable just fine.

      The issue is either to do with the code being broken (erroneous cast?) or the example being incorrect.

      Thanks

      Attachments

        Activity

          People

            Unassigned Unassigned
            jdcockrill James Cockrill
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: