[ 
https://issues.apache.org/struts/browse/TILES-338?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Zach Bailey updated TILES-338:
------------------------------

    Description: 
In AddAttributeTag#doAfterBody:

/**
     * Save the body content of this tag (if any).
     *
     * @return It returns <code>SKIP_BODY</code>.
     */
    public int doAfterBody() {
        if (value == null && bodyContent != null) {  //bug here
            value = bodyContent.getString();
            type = "string";
        }
        return (SKIP_BODY);
    }

The value of this tag is only being updated if there is not already a value 
set. So, when this tag is used twice in succession on a page, it will always 
only use the first "value" ever set!!!

I looked back at the older Tiles 2.0.6 version we were using and the code is 
correct in that version - there is no "value == null" check. So, it looks as 
though someone added this little check at some point in the 2.1 release, but it 
seems to severely break things (at least for me!)

I see two ways of fixing this - 

1.) Simply remove the value == null check, or if this check is in place for a 
reason,

2.) Reset value to null after each execution of the tag in doEndTag, or 
doFinally() from the TryCatchFinally interface:

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/TryCatchFinally.html


  was:
In AddAttributeTag#doAfterBody:

/**
     * Save the body content of this tag (if any).
     *
     * @return It returns <code>SKIP_BODY</code>.
     */
    public int doAfterBody() {
        if (value == null && bodyContent != null) {  //bug here
            value = bodyContent.getString();
            type = "string";
        }
        return (SKIP_BODY);
    }

The value of this tag is only being updated if there is not already a value 
set. So, when this tag is used twice in succession on a page, it will always 
only use the first "value" ever set!!!

I looked back at the older Tiles 2.0.6 version we were using and the code is 
correct in that version - there is no "value == null" check. So, it looks as 
though someone added this little check at some point in the 2.1 release, but it 
seems to severely break things (at least for me!)

I see two ways of fixing this - 

1.) Simply remove the value == null check, or if this check is in place for a 
reason,

2.) Reset value to null after each execution of the tag in doEndTag, or 
doFinally() from the TryCatchFinally interface:

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/TryCatchFinally.html

        Summary: AddAttributeTag only uses the first "value" ever set when 
value is body content  (was: AddAttributeTag only uses the first "value" ever 
set)

Thinking about this more - this will of course only happen if the value is 
being pulled from the body content. If the value is set via the "value" 
attribute, the JSP container will call the setValue method and the value will 
be handled correctly.

So, I think I can understand why this value == null check was added - 
essentially, it allows the value attribute to "trump" or supersede the body 
content. Unfortunately, it has led to this bug. So, I believe my solution #2 as 
outlined above would be the best in this case which allows us to keep the 
existing behavior.

> AddAttributeTag only uses the first "value" ever set when value is body 
> content
> -------------------------------------------------------------------------------
>
>                 Key: TILES-338
>                 URL: https://issues.apache.org/struts/browse/TILES-338
>             Project: Tiles
>          Issue Type: Bug
>          Components: tiles-jsp (jsp support)
>    Affects Versions: 2.1.0
>            Reporter: Zach Bailey
>
> In AddAttributeTag#doAfterBody:
> /**
>      * Save the body content of this tag (if any).
>      *
>      * @return It returns <code>SKIP_BODY</code>.
>      */
>     public int doAfterBody() {
>         if (value == null && bodyContent != null) {  //bug here
>             value = bodyContent.getString();
>             type = "string";
>         }
>         return (SKIP_BODY);
>     }
> The value of this tag is only being updated if there is not already a value 
> set. So, when this tag is used twice in succession on a page, it will always 
> only use the first "value" ever set!!!
> I looked back at the older Tiles 2.0.6 version we were using and the code is 
> correct in that version - there is no "value == null" check. So, it looks as 
> though someone added this little check at some point in the 2.1 release, but 
> it seems to severely break things (at least for me!)
> I see two ways of fixing this - 
> 1.) Simply remove the value == null check, or if this check is in place for a 
> reason,
> 2.) Reset value to null after each execution of the tag in doEndTag, or 
> doFinally() from the TryCatchFinally interface:
> http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/TryCatchFinally.html

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to