GitHub user brettryan opened a pull request:

    https://github.com/apache/tiles/pull/5

    Add support for add-list-attribute to render expressions

    When using expressions using the following example:
    
        <put-list-attribute name="breadcrumbs" cascade="true" inherit="true">
          <add-list-attribute>
            <add-attribute expression="${customer.id}"/>
            <add-attribute expression="/customers/${customer.id}/info"/>
          </add-list-attribute>
          <add-list-attribute>
            <add-attribute value="Orders"/>
            <add-attribute expression="/customers/${customer.id}/orders"/>
          </add-list-attribute>
        </put-list-attribute>
    
    We first encounter an NPE when attempting to access this object. This is 
due to 
[Attribute#toString](https://tiles.apache.org/framework/apidocs/org/apache/tiles/Attribute.html#toString())
 returning the value `null` which with the container attempting to turn this 
into a binary array cases an NPE. This has been resolved by returning the 
string `"null"`.
    
    For the list attributes I have chosen to recursively process any lists 
encountered within 
[AbstractAttributeEvaluator#evaluate](https://tiles.apache.org/framework/apidocs/org/apache/tiles/evaluator/AbstractAttributeEvaluator.html#evaluate(org.apache.tiles.Attribute,%20org.apache.tiles.request.Request)
 to clone each attribute to a new instance with the value set to the evaluated 
expression.
    
    **NOTE**: This solution comes with one caveat that is semi-intentional and 
you may choose to reject the pull request on this point. Previously a 
[ListAttribute](https://tiles.apache.org/framework/apidocs/org/apache/tiles/ListAttribute.html)
 would be exposed to the view requiring consumers to make references to the 
attributes `value` property before accessing the index to the list.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/brettryan/tiles feature_list_att_exp_support

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/tiles/pull/5.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #5
    
----
commit 515dc95746aa33bf1472b917d924af3c0bc2dae1
Author: Brett Ryan <brett.r...@gmail.com>
Date:   2015-07-08T15:19:47Z

    Correct NPE with Attribute#toString.

commit 41759e82bbc1b4ec15878caba6bf6b659d256886
Author: Brett Ryan <brett.r...@gmail.com>
Date:   2015-07-08T15:26:21Z

    Added support for list attributes to have expressions.
    
    - This will certainly need review as the current implementation breaks 
current behavior with relation to attributes from list attributes being exposed 
to the view, while simple attributes are not.
    - This implementation maps everything to the objects represented type where 
possible, though due to current requirements elements must remain to be an 
attribute wrapping the value.
    - Attribute#getExpression is evaluated and set against a cloned version of 
Attribute#setValue.

commit be97c75393f9d72cfebe717146db88608427429d
Author: Brett Ryan <brett.r...@gmail.com>
Date:   2015-06-14T23:49:29Z

    Added git ignore/attributes.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to