You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by DavidCAIT <dz...@cait.org> on 2009/06/02 03:14:16 UTC

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.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [OT} Re: Iterating over a List of Lists

Posted by st...@gmail.com.
someone stole my bike!

On Tue, Jun 2, 2009 at 9:39 AM, Dave Newton <ne...@yahoo.com> wrote:

> Jim Kiley wrote:
>
>> I had no idea I was in the presence of royalty.
>>
>
> There's a lotta things about me you don't know anything about, Jim. Things
> you wouldn't understand. Things you couldn't understand. Things you
> *shouldn't* understand.
>
> ....
>
> I've always been a little disturbed by how much I enjoy that movie :/
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

[OT} Re: Iterating over a List of Lists

Posted by Dave Newton <ne...@yahoo.com>.
Jim Kiley wrote:
> I had no idea I was in the presence of royalty.

There's a lotta things about me you don't know anything about, Jim. 
Things you wouldn't understand. Things you couldn't understand. Things 
you *shouldn't* understand.

....

I've always been a little disturbed by how much I enjoy that movie :/

Dave

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


Re: Iterating over a List of Lists

Posted by Jim Kiley <jh...@summa-tech.com>.
I had no idea I was in the presence of royalty.

On Tue, Jun 2, 2009 at 10:29 AM, Dave Newton <ne...@yahoo.com> wrote:

> DavidCAIT wrote:
>
>> My JSP code looks like:
>>
>> <s:iterator value="myList" status="outerStat">
>>  <s:iterator value="myList[#outerStat.index]" status="innerStat">
>>    <s:textfield value="%{property}"
>>      name="myList[%{#outerStat.index}][%{#innerStat.index}].property"/>
>>  </s:iterator>
>> </s:iterator>
>>
>
> I did something very similar to this quite some time ago, although it was
> actually a little worse (another layer, the name of one of the properties
> was dynamic) and was crowned the King of OGNL for my efforts.
>
> Maybe search the archives--there shouldn't be an issue doing things like
> this if things are set up right.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Jim Kiley
Senior Technical Consultant | Summa
[p] 412.258.3346
http://www.summa-tech.com

Re: Iterating over a List of Lists

Posted by Dave Newton <ne...@yahoo.com>.
DavidCAIT wrote:
> My JSP code looks like:
> 
> <s:iterator value="myList" status="outerStat">
>   <s:iterator value="myList[#outerStat.index]" status="innerStat">
>     <s:textfield value="%{property}"
>       name="myList[%{#outerStat.index}][%{#innerStat.index}].property"/>
>   </s:iterator>
> </s:iterator>

I did something very similar to this quite some time ago, although it 
was actually a little worse (another layer, the name of one of the 
properties was dynamic) and was crowned the King of OGNL for my efforts.

Maybe search the archives--there shouldn't be an issue doing things like 
this if things are set up right.

Dave

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


RE: Iterating over a List of Lists

Posted by Steve <st...@sjlt.co.uk>.
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:dzazeski@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:dzazeski@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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


RE: Iterating over a List of Lists

Posted by DavidCAIT <dz...@cait.org>.
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:dzazeski@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

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


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


RE: Iterating over a List of Lists

Posted by Steve <st...@sjlt.co.uk>.
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:dzazeski@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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