[
https://issues.apache.org/struts/browse/WW-1780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40363
]
Kris Coolsaet commented on WW-1780:
-----------------------------------
Adding an indexed getter like
public String getTest (int index) {
return "dummy";
}
does not work. (I forgot to copy it from my original test.) There is also a
setCommand by the way - although that does not seem necessary.
Although according to <a
href="http://www.ognl.org/2.6.9/Documentation/html/LanguageGuide/indexing.html#N10189"/>the
OGNL documentation</a>, this is not really necessary, further adding
public String[] getTest () {
return null;
}
public void setTest (String[] array) {
// do nothing
}
does not help either. (Instead of 'return null' I also tried the alternative
'return new String[0]'.)
> 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.