John
Made few changes and code worked fine.
Would like to extend this so that it will work for handling Dynamic
table situation-- Let me explain
If u see in Action form reset method I initialized it to 5 (num="5 "for
testing) so the page loads with five empty rows, But we have a
requirement where the user can add more rows to the table and click
submit.
1. Action form code:
private ArrayList personList;
public void reset(ActionMapping mapping, HttpServletRequest request){
this.personList = new ArrayList();
// String num = request.getParameter("personListLength");
String num ="5";
try {
if (num != null) {
int len = Integer.parseInt(num);
for (int i = 0; i < len; i++)
this.personList.add(new PersonBean());
}
}catch (NumberFormatException e) {
e.printStackTrace();
}
}
public PersonBean getPerson(int ndx) {
return (PersonBean) personList.get(ndx);
}
public void setPersonList(int ndx, PersonBean p) {
personList.set(ndx, p);
}
public ArrayList getPersonList(){
return this.personList;
}
2. jsp
<TABLE id="mytable">
<logic:present name="personList">
<logic:iterate id="person" name="dynaTableForm" property="personList"
type="com.learning.struts.PersonBean" >
<tr>
<td>
<html:text name="person" property="firstName" indexed="true"/>
</td>
<td>
<html:text name="person" property="phoneNo" indexed="true"/>
</td>
</tr>
</logic:iterate>
</logic:present>
</TABLE>
3.PersonBean:
public class PersonBean implements Serializable
{
String firstName;
String phoneNo;
public PersonBean()
{
super();
}
public String getFirstName()
{
return firstName;
}
public void setFirstName(String newFirstName)
{
firstName = newFirstName;
}
public String getPhoneNo()
{
return phoneNo;
}
public void setPhoneNo(String newPhoneNo)
{
phoneNo = newPhoneNo;
}
}
Let me know if u need any further info.
Thanks
>>> [EMAIL PROTECTED] 06/12/03 01:57PM >>>
I believe indexed attributes were first, then Arron contributed nested
and life got easier. Stick with it and don't go backwards.
-john
-----Original Message-----
From: Adam Hardy [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 11, 2003 11:52 PM
To: Struts Users Mailing List
Subject: Re: what setters do i implement in an indexed tag --NewBie
question
Sashi, your person bean must have getName(), setName() and getPhoneNo(),
setPhoneNo().
Everybody: I haven't come across the html:taglib indexed property
before. This seems to do what nested: tags do - is this functional
overlap?
Generally with JST taglib as well, there seems to be a wide choice of
taglibs to use - is this going to consolidate at some point in struts'
development?
Adam
Sashi Ravipati wrote:
> 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]