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

ViewPreparer does not deep copy Attributes of AttributeContext

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.2
    • 2.1.3
    • tiles-api
    • None
    • Tomcat 6.0, Tiles 2.1.2

    Description

      When using a custom ViewPreparer the Attribute objects of the AttributeContext are apparently not deep-copied for the execute() function call.
      So when the code is executed the first time and an attribute of the current tiles definition is set (changed from its original value) it will have the same changed value the next time the definition/preparer is called. Intended behaviour should be that the execute() function recieves a copy of the AttributeContext and copies of the included Attributes so that the original value is not touched when the preparer prepares the definition for the JSP file.

      Simple test case:

      tiles-def.xml:

      <tiles-definitions>
      <definition name="test.definition" template="/jsp/test.jsp" preparer="TestPreparer">
      <put-attribute name="testAttr" value="1" />
      </definition>
      </tiles-definitions>

      TestPreparer.java:

      public class TestPreparer implements ViewPreparer {
      public void execute(TilesRequestContext requestContext, AttributeContext attrContext)

      { int testValue = Integer.parseInt(attrContext.getAttribute("testAttr").getValue().toString()); // testValue (value of testAttr) should be 1, since that is what we defined in tiles-defs.xml // now we change testAttr (increment by 1) and save it - so it should always be 2 testValue++; attrContext.getAttribute("testAttr").setValue(""+testValue); }

      }

      test.jsp:

      <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
      value of testAttr:
      <tiles:insertAttribute name="testAttr" />

      If you keep hitting the refresh button for the test definition in the browser, the value of testAttr increases each time, although it should be 2 always.

      Attachments

        Activity

          People

            brenmcguire Antonio Petrelli
            ulsamern Nino Ulsamer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: