kanishk
kanishk

Reputation: 743

Struts iterator not working

Despite finding many other such questions and spending a lot of time on them, I am unable to figure out what is going wrong with my iterator.

I have a list of objects, which I want to iterate and display various properties of each object in text fields. I have setup iterator like in the code below, but somehow no rows appear.

This is the jsp :

<s:form theme="simple" id="salaryDetails" name="salaryDetails">
    <table>
        <tr>
            <td>Name</td>
            <td>Basic</td>
            //etc//
        </tr>

        <s:iterator value="salaryDetail" var="salaries">
            <tr>
                <td><s:textfield name="emplName" value="%{employeeCode}"/></td>
                <td><s:textfield name="basic"    value="%{basic}"/></td>
            </tr>
        </s:iterator>
    </table>
</s:form>

The output of this form is just the row with the headings whereas I expect rows of text fields with some data pre - populated. The iterator does not seem to be working. I am sure that the list contains data because I am able to print it on the console in the action class.

Please advice!!

Its really urgent.

Thanks

Upvotes: 2

Views: 3281

Answers (1)

Umesh Awasthi
Umesh Awasthi

Reputation: 23587

There seems some issue with your action.either you have not defined public getter for you list or you are not using the Bean property properly. a quick run of your example is working fine for me here is the sample code

public classDemoAction extends ActionSupport{
 private List<SalaryDetail> salaryDetail;
 // getter ans setter for this

 public String execute() throws Exception{
   SalaryDetail detail=new SalaryDetail();
   detail.setName("a");
   salaryDetail=new ArrayList<SalaryDetail>();
   SalaryDetail detail1=new SalaryDetail();
   detail1.setName("a");
   salaryDetail.add(detail);
   salaryDetail.add(detail1);
   return SUCCESS;

 }

}

here is the jsp code

 <s:form theme="simple" id="salaryDetails" name="salaryDetails">
        <table>
        <tr>
            <td>Name</td>
            <td>Basic</td>
            //etc//
        </tr>

        <s:iterator value="salaryDetails">
            <tr>
                <td><s:textfield name="emplName" value="%{name}"/></td>

            </tr>
        </s:iterator>
    </table>

just cross check your code there is either some typo or might be inconstancy with naming

Upvotes: 1

Related Questions