Jason,
I believe you need a
public User getUser(int index)
{
return (users[i]);
}
For the examples I sent you, I have the following form:
public final class ParametersForm extends ActionForm
{
// --------------------------------------------------- Instance Variables
/**
* The parameter list
*/
private Vector parameterList = new Vector();
// ----------------------------------------------------------- Properties
/**
* Return the list of parameters
*/
public Vector getParameterList()
{
return(this.parameterList);
}
/**
* Set the list of parameters
*
* @param parameterList The new list
*/
public void setParameterList(Vector parameterList)
{
this.parameterList = parameterList;
}
/**
* Get a particular parameter from the parameterList, based on index
*
* @param index The index of the parameter to retrieve
*/
public Parameter getParameter(int index)
{
return (Parameter)parameterList.elementAt(index);
}
}
and I obviously have get/set methods in my Parameter object to get the parameter
variables.
Cheers.
Dave
Jason Rosenblum <[EMAIL PROTECTED]> on 06/27/2001
12:20:51 PM
Please respond to [EMAIL PROTECTED]
To: "'[EMAIL PROTECTED]'"
<[EMAIL PROTECTED]>
cc: (bcc: David Hay/Lex/Lexmark)
Subject: Indexed Properties
Hello all,
I'm trying to get my code to work with indexed properties. Thanks to Dave Hay
and his Struts tweak, I was able to generate input types like this:
<input type="text" name="users[0].username" size="12" value="">
<input type="text" name="users[0].role" size="12" value="">
using the following Struts tags:
<html:text name="users" property="username" size="12" indexed="true"/>
<html:text name="users" property="role" size="12" indexed="true"/>
The problem is that I cannot get my ActionForm to pick up these input fields. I
wrote several setters and getters in my ActionForm:
/**
* Return the users.
*/
public String getUsers(int i) {
return (users[i].getUsername());
}
/**
* Set a user.
*
* @param user
* @param index
*/
public void setUsers(int i, String user) {
this.users[i].setUsername(user);
}
/**
* Return the users.
*/
public User[] getUsers() {
return (this.users);
}
/**
* Set a user.
*
* @param user list
*/
public void setUsers(User[] users) {
this.users = users;
}
/**
* Return the roles.
*/
public String getRoles(int i) {
return (users[i].getRole());
}
/**
* Set a role.
*
* @param role
* @param index
*/
public void setRoles(int i, String role) {
this.users[i].setRole(role);
}
/**
* Return the roles.
*/
public User[] getRoles() {
return (this.users);
}
/**
* Set a role.
*
* @param role list
*/
public void setRoles(User[] roles) {
this.users = users;
}
Do you see anything wrong with this scheme? Currently, the ActionForm returns
null for all items in the User[] when I call any of the get methods. Please
help.
~Jason