struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adam pinder <>
Subject RE: Inserting data into nested collections
Date Mon, 01 Mar 2010 18:31:35 GMT

i used the following and it worked ok with struts2.
In JSP :-
<s:textfield name="opportunity.opportunityItem[0].quantity" value="12" size="5" maxlength="5"
theme="simple" cssClass="mandatory" onblur="setListPrice(%{#rowstatus.index})"/>

In Action, i have a get/set for opportunity which is an object with the following property
(with get/setters)
     private Collection opportunityItems = new ArrayList(0);

and the following additional method in the opportunity class
      public OpportunityItem getOpportunityItem(int occ)
       Collection coll = this.getOpportunityItems();
       Object[] objs = coll.toArray();
       OpportunityItem oppItem = null;
       if (objs[occ] instanceof OpportunityItem)
        oppItem = (OpportunityItem)objs[occ]; 
       return oppItem;

you could cast the collection to ArrayList and use .get(occ) but i wanted to be able to change
collection type.
struts2 then takes "opportunity.opportunityItem[0].quantity" and does...
i've found the utility methods are sometimes needed to handle arrays.
if it was just a repeating field you could define a String[] and have the fields with the
same name and struts would populate it for you.
Do you have a story that started on Hotmail? Tell us now
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message