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

Don Brown resolved WW-1780.
---------------------------

       Resolution: Duplicate
    Fix Version/s:     (was: 2.0.8)

I've confirmed this is an issue but it seems to be in OGNL, not Struts 2.  I 
opened up a ticket over there: http://jira.opensymphony.com/browse/OGNL-79

> Indexed (bean) properties do not work when property is not a real array
> -----------------------------------------------------------------------
>
>                 Key: WW-1780
>                 URL: https://issues.apache.org/struts/browse/WW-1780
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Actions, Value Stack
>    Affects Versions: 2.0.6
>            Reporter: Kris Coolsaet
>            Priority: Minor
>
> OGNL documentation states that for an indexed property (like test[133] ) an 
> indexed getter and setter of the form
>    public String getTest (int index)
>    public void setTest (int index, String value)
> should be sufficient. In other words: there need not be a property (test) 
> which corresponds to a real array of strings.
> This does not seem to work in Struts 2.
> Sample test case:
> Create an action class Test.action containing the following code
>     private String command = "no command";
>     
>     public String getCommand () {
>         return command;
>     }
>     public void setTest (int index, String value) {
>         command = "test["+index+"]="+value;
>     }
> and a JSP-page test.jsp which contains something like
>         <h1>
>             <s:property value="command"/>
>         </h1>
> Link them to an action Test in the struts.xml file
>         <action name="Test" class="Test">
>             <result>/test.jsp</result>
>         </action>
> and type in the following url: Test.action?test[133]=xxx
> The page displays 'no command' instead of 'test[133]=xxx' as I would expect.
> (A variant of this, using strings as indices instead of integers, does also 
> not work.)
> There are many use cases for this functionality. For example, consider a long 
> table with many columns, in which every row
> displays some element of a large database table (only a small selection of 
> the entire table is displayed). The leftmost column contains checkboxes. A 
> single 'delete'-button will be used to remove all checked items from the 
> database.
> In this case, it would be nice for the individual checkboxes to carry names 
> like 'delete[123]', 'delete[255]', ..., where the index is the unique 
> database key of the record. The 'setDelete(int index)' method of the action 
> could then simply add the sequence number to a set, while the execute method 
> could simply iterate over the set. There would then be no need for the action 
> to create a big array of booleans, one for each record in the database.

-- 
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