Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

values of multiple parameters not getting set with logic:iterate

Status
Not open for further replies.

jgalzic

Programmer
Apr 4, 2005
2
US
I have a form in which I'd like to enter several rows (5 at a time) of information. 5 blank rows get displayed as expected but when I try to submit the information as a user, I am only getting back the values for the first row and nothing seems to get set for the other 4 rows even though there were values set in the browser. Not sure what's wrong. Does any one have any suggestions on what could be causing this?
The jsp code is:

<html:form action="AddEmployees.do">
<logic:iterate name="AddEmployeesForm" property="employees" id="row" scope="request">
Name: <html:text name="row" property="name" size="50" maxlength="120"/>
Email: <html:text name="row" property="email" size="50" maxlength="120"/>
<html:submit/>
</logic:iterate>
</html:form>

The action, AddEmployees.do is mapped to the AddEmployeesForm. It looks like:


public final class AddEmployeesForm extends ActionForm
{
private ArrayList m_employees = new ArrayList();

private Log m_log = LogFactory.getLog(this.getClass());

public AddEmployeesForm()
{
addEmployee(new NewEmployee());
addEmployee(new NewEmployee());
addEmployee(new NewEmployee());
}

public List getEmployees() { return m_employees; }
public void setEmployees(ArrayList employees) { m_employees = employees; }

public void setName(String name)
{
m_log.info("setName: " + name);
}
public void setEmail(String email)
{
m_log.info("setEmail: " + email);
}
public void addEmployee(NewEmployee employee)
{
m_employees.add(employee);
}
public int getSize() { return m_employees.size(); }

}

and NewEmployee is a separate class with name and email as properties with public getters and setters:

public class NewEmployee
{
private String m_name = new String();
private String m_email = new String();
public NewEmployee()
{
}

public String getName() { return m_name; }
public void setName(String name) { m_name = name; }

public String getEmail() { return m_name; }
public void setEmail(String email) { m_email = email; }
}

Thanks,
Justin
 
I could be wrong on this, so take the information with a grain of salt as I'm new to struts, but doesn't your property in your .jsp have to be m_employees, instead of just employees?

from this declaration: private ArrayList m_employees = new ArrayList();

I haven't done anything with iterator yet, so I'm not sure how it works. If I'm wrong, how does
<logic:iterate name="AddEmployeesForm" property="employees" id="row" scope="request">

the employees property attach itself to your code, just out of curiosity.
 
No because when the form requests for the property named 'employees', it will actually call the appropriate getter method, and for this case, it will be 'getEmployees'.

Justin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top