You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mu...@aol.com on 2009/03/02 02:13:51 UTC

Re: Nested iterator struts 2.1.6 -- automatically rebuild the collection

Hi Phan,
??? I wrestled with this problem until I was out of my depth.?

I tried it with an ArrayList<ArrayList<Double>> initialized as 

[[1.0, 2.0, 3.0], [7.0, 8.0, 9.0]]
and on resubmission the data keeps getting flattened to 

[[[1.0]], [[2.0]], [[3.0]], [[7.0]], [[8.0]], [[9.0]]]

:(

Here is what I have dug up so far and hopefully someone who knows the code better might take it further: 

The ArrayList is represented in the action by an instance of com.opensymphony.xwork2.util.XWorkList? (a subclass of ArrayList). 
It overrides the ArrayList?addAll(Collection c) method as listed below. It??loops through the collection and delegates to the add(Object element). The element (which in our case is the inner ArrayList) is passed by add(Object element)?to the convert method which *does not check if it is a collection and loop*. I think that is the crux of the problem.



?@Override
??? public boolean addAll(Collection c) {
??????? if (c == null) {
??????????? throw new NullPointerException("Collection to add is null");
??????? }

??????? for (Object aC : c) {
??????????? add(aC);
??????? }

??????? return true;
??? }



? @Override
??? public boolean add(Object element) {
??????? element = convert(element);

??????? return super.add(element);
??? }



private Object convert(Object element) {
??????? if ((element != null) && !clazz.isAssignableFrom(element.getClass())) {
??????????? // convert to correct type
??????????? if (LOG.isDebugEnabled()) {
??????????????? LOG.debug("Converting from " + element.getClass().getName() + " to " + clazz.getName());
??????????? }

??????????? Map<String, Object> context = ActionContext.getContext().getContextMap();
??????????? element = conv.convertValue(context, null, null, null, element, clazz);? //My comment -- conv is a reference to an instance of XWorkConverter
??????? }

??????? return element;
??? }


Sorry I could not solve the problem satisfactorily
Chris

==================================


-----Original Message-----
From: Phan, Hienthuc T <hi...@merck.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Mon, 23 Feb 2009 8:24 pm
Subject: RE: Nested iterator struts 2.1.6 -- automatically rebuild the collection





Yeah, I think my OGNL expression usage is not correct but I tried
several combination, none of them work.  

If I declare my variable as:
ArrayList<ArrayList<User>> userList = new ArrayList<ArrayList<User>>();
//getter and settter

I tried this on JSP and it didn't work.
<s:iterator value="userList" id="userList" status="outerStatus">
    <s:iterator value="#userList" status="innerStatus">
        <s:textfield
name="userList[%{outerStatus.index}].[%{innerStatus.index}].name"/>
        <s:textfield
name="userList[%{outerStatus.index}].[%{innerStatus.index}].email"/>
        <s:textfield
name="userList[%{outerStatus.index}].[%{innerStatus.index}].address"/>
    </s:iterator>
</s:iterator>

-----Original Message-----
From: musomesa@aol.com [mailto:musomesa@aol.com] 
Sent: Friday, February 20, 2009 7:27 PM
To: user@struts.apache.org
Subject: Re: Nested iterator struts 2.1.6 -- automatically rebuild the
collection


 
What do you have inside the iterator tag?? Hard to diagnose without
knowing what you have. Some possible causes:
A a possible OGNL expression error inside your iterator tag. 
If the Sample objects are not built-in java objects (String, Date..) you
might be having type conversion problems? 
Are you sending the information back to the same action or is there a
possible mix-up in the attributes of your tags
Chris


 


 

-----Original Message-----
From: Phan, Hienthuc T <hi...@merck.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Mon, 9 Feb 2009 5:46 pm
Subject: Nested iterator struts 2.1.6 -- automatically rebuild the
collection










Hi,

Using <s:iterator ..> tag, how do you instruct struts to rebuild the
collection automatically?

I have a List of List of Sample objects
I use <s:iterator > tag to loop through and display data for user to
make changes
The displaying part is OK; however, when the form is submitted, the List
of List of Sample objects is not populated.

In Struts 1.x, the tag <logic:iterator > was used and if we add
indexed=true for each element inside the <
logic:iterator > tag, Struts
automatically rebuild the collection.  Is there a way that it can
accomplish with <s:iterator>?

Thank you.


Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or
MSD and in Japan, as Banyu - direct contact information for affiliates
is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and
then delete it from your system.



 

Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or
MSD and in Japan, as Banyu - direct contact information for affiliates is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and
then delete it from your system.


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