Sarjith Pullithodi
Sarjith Pullithodi

Reputation: 89

why my ArrayList is not populating in struts (1.3)

My ActionForm has the following field.

//form
private ArrayList<String> chargeIds = new ArrayList<String>();  
public ArrayList<String> getChargeIds() {  
    return chargeIds;  
}  
public void setChargeIds(ArrayList<String> chargeIds) {  
    this.chargeIds = chargeIds;  
}//form

And in my jsp I wrote like below:-

//jsp
.... 

    <html:form action="/PurchaseOrderAction" styleId="defaultForm">
    <table> 
    <logic:iterate id="element" name="<%= Constants.SHOPPING_ORDER_CART_ITEMS %>" type="mypackage.ItemBean" >
    <tr><td>
     <logic:Equal name="element" property="promotedItem" value="true">
           <html:select property="chargeIds" styleClass="transperentList" indexed="true">
               <html:options collection="<%=Constants.ALL_CHARGES %>" property="key" labelProperty="name" />
        </html:select>
      </logic:Equal>
    <logic:notEqual name="element" property="promotedItem" value="true">
      <bean:write name="element" property="chargeName"/>
    </logic:notEqual>
    </tr></td>

.....
//jsp

I am getting jsp populated properly... but when i Submit the form.. i am not getting any value in the arraylist of my formbean.

any idea how? I am using struts 1.3 (unfortunately not able to update, as the project started from very long back, and i am a new member of the team).

Thanks.

Sarjith

Upvotes: 4

Views: 2884

Answers (2)

Carlos Pastor
Carlos Pastor

Reputation: 999

I don't know if this will solve your problem, but according to your answer if you only want to select one of the options, the property of the html:select should be a String object and not an Arraylist. So your HTML should look something like this:

<html:select property="selectedChargeId" styleClass="transperentList" indexed="true">
    <html:options collection="chargeIds" property="key" labelProperty="name" />
</html:select>

And then your form should have these variables (with their respective getters and setters):

private ArrayList<String> chargeIds;
private String selectedChargeId;

It always works for me, I hope it solves your problem.

Upvotes: 0

Alex
Alex

Reputation: 11579

Try to change ArrayList to String[] in your form object.

Upvotes: 2

Related Questions