Hi David,

My code doesn't include an editing capability so I don't have any working
code that I can cut and paste. Also I have not tried sending a List back
from a JSP page.

Are you getting any sub-lists back or are they all null?

Cheers,

Steve

-----Original Message-----
From: DavidCAIT [mailto:dzaze...@cait.org] 
Sent: 02 June 2009 14:13
To: user@struts.apache.org
Subject: RE: Iterating over a List of Lists


Thanks for the reply.

I am able to display the contents of the nested list (as indicated in your
example). However, I want to make the list contents editable and return them
to the Struts action. For example, something similar to:

<s:iterator value="outerList">
<tr>
<s:iterator>
<td><s:textfield value="%{listItem}"/></td>
</s:iterator>
</tr>
</s:iterator>

Displaying the contents of the nested list is not the problem. I'm
experiencing problems indexing the textfields when returning the list to the
Struts Action. Perhaps the following order of events will clarify my
problem:

1. First Struts Action retrieves records from the database and populates the
List<List<Objects>>.
2. JSP page correctly displays all of the List<List<Objects>>.
3. (broken step) Second Struts Action would like to receive the
List<List<Objects>> and save them back to the database.

The problem seems to be that my JSP page does not properly index the
textfield elements. Struts is then unable to parse the results back into the
List<List<Objects>> for the Second Action. So what names should I give the
different textfields to allow Struts to parse them into a
List<List<Objects>>?


Steve H. wrote:
> 
> This works for me
> 
> <s:iterator value="outerList">
> <tr>
> <s:iterator>
> <td><s:property/></td>
> </s:iterator>
> </tr>
> </s:iterator>
> 
> My inner list is a list of Strings.
> 
> This code gives me one innerList list per line
> 
> Hope this helps,
> 
> Steve
> 
> -----Original Message-----
> From: DavidCAIT [mailto:dzaze...@cait.org] 
> Sent: 02 June 2009 02:14
> To: user@struts.apache.org
> Subject: Iterating over a List of Lists
> 
> 
> Hello,
> 
> I am trying to use a nested List<List<MyObject>> with a Struts 2 Action
> and
> a JSP page. I would like to iterate through the JSP page to display the
> existing data, allow the user to edit the data, and post the form to a
> second Action. However, my second Struts Action always receives back a
> null
> list. I think that my indexing in the JSP page is incorrect. Does anyone
> have any suggestion about the correct way to index a nested list on the
> JSP
> page?
> 
> This is how I am currently setting my indices:
> 
> myList[0][0].property
> myList[0][1].property
> ....
> myList[1][0].property
> .......
> 
> My JSP code looks like:
> 
> <s:iterator value="myList" status="outerStat">
>        <s:iterator value="myList[#outerStat.index]" status="innerStat">
>                <s:textfield
> name="myList[%{#outerStat.index}][%{#innerStat.index}].property"
> value="%{property}" />
>         </s:iterator>
> </s:iterator>
> 
> Inside my second Struts action, I have the following code (the first
> action
> merely retrieves the list from the database and it works correctly since
> the
> JSP does populate correctly with all of the db records):
> 
> private List<List<MyObject>> myList = new ArrayList<List<MyObject>>();
> 
> public List<List<MyObject>> getMyList() { return myList; }
> 
> public void setMyList(List<List<MyObject>> numbers) { myList = numbers; }
> 
> // this execute method is called when posting the form and always returns
> null
> // when the user is done updating the information
> // even though the first action correctly populated the JSP page
> public String execute() {
>   for (List<MyObject> theList : myList) {
>       if (theList == null) {
>          System.out.println("received a null list");
>       }
>    }
> }
> 
> Thanks!
> -- 
> View this message in context:
>
http://www.nabble.com/Iterating-over-a-List-of-Lists-tp23824944p23824944.htm
> l
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Iterating-over-a-List-of-Lists-tp23824944p23832301.htm
l
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to