Assuming you're NOT using the lazy initialization, you could do it like
this...



1) your iterate will need to specify the type of the nested class:

<logic:iterate id="person" name="myFormBean" property="personList"
type="com.mydom.myproject.struts.Person>

Where the Person class has just the standard accessors for name and
phoneNo.


2) Your myFormBean will have the special accessors for indexing:

    // SPECIAL ACCESSORS FOR INDEXING NEEDED
    public Person getPersonList(int ndx) {
        return (PersonForm) personList.get(ndx);
    }
    public void setPersonList(int ndx, PersonForm p) {
        personList.set(ndx, p);
    }


3) Assuming you don't already know the size of your personList, your
reset method
will initialize it and create the empty Person objects to fill with the
data:

    public void reset(ActionMapping mapping, HttpServletRequest request)
{

        this.personList = new ArrayList();

        String num = request.getParameter("personListLength");
        try {
            if (num != null) {
                int len = Integer.parseInt(num);
                for (int i = 0; i < len; i++)
                    this.personList.add(new PersonForm());
            }
        } catch (NumberFormatException e) {
            //...
        }
    }

This assumes the prep action that entered the jsp figured out the size
of the list
and set it into a hidden in the jsp in a field named personListLength.

-john

-----Original Message-----
From: Sashi Ravipati [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 11, 2003 1:19 PM
To: [EMAIL PROTECTED]
Subject: what setters do i implement in an indexed tag --NewBiequestion


Can some body help in as how to define get and set methods when we use
indexed tags.

eg:

<logic:iterate id="person" name="myFormBean" property="personList">
  <tr>
    <td>
      <bean:write name="person" property="name"/>
      <html:hidden name="person" property="name" indexed="true"/>
    </td>
    <td>
      <html:text name="person" property="phoneNo" indexed="true"/>
    </td>
  </tr>
</logic:iterate>

What will be the get and set methods. 

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to