The problem is that your getUsers() return an array of User instances while
your getUsers(int i) returns a String.
As a result the PropertyDescriptor class for the users property will
consider the User class as the type of your property, and will check the
existence of User getUsers(int i) and void setUser(int i, User user).
You must make sure that indexed and non-indexed read/write methods use the
same type.
Fr.
-----Original Message-----
From: Jason Rosenblum [mailto:[EMAIL PROTECTED]]
Sent: 27 June 2001 18:21
To: '[EMAIL PROTECTED]'
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
************************************************************************
The information in this email is confidential and is intended solely
for the addressee(s).
Access to this email by anyone else is unauthorised. If you are not
an intended recipient, you must not read, use or disseminate the
information contained in the email.
Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of Capco.
http://www.capco.com
***********************************************************************