History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: WW-474
Type: Bug Bug
Status: Closed Closed
Resolution: Cannot Reproduce
Priority: Major Major
Assignee: Unassigned
Reporter: Bhavin Kamani
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
WebWork

Ability to dynamically create array of Objects from a given request

Created: 18/Feb/04 06:07 AM   Updated: 19/Feb/04 10:09 AM
Component/s: Interceptors
Affects Version/s: 2.1
Fix Version/s: 2.1

Environment: Windows XP, Tomcat 5.0.16, JDK 1.4.1_03


 Description  « Hide
First, Kudos to team for creating a very simple yet powerful framework.

I have a situation where I would like to receive an unknown no. of user names from a web page. Using DHTML I am dynamically creating text fields as user[0], user[1]....

My FormAction.java looks like following

public class FormAction extends ActionSupport {
    private String[] users = null;
    public String[] getUsers() {
        return users;
    }
    public void setUsers(String[] value) {
        this.users = value;
    }
    public String processForm() {
        return SUCCESS;
    }
}

However, on submitting the action request, I get
java.lang.InstantiationException: [Ljava.lang.String; error. Even if I initialize the String array, it still does not work.

Not sure if this is a bug or a new feature request. Hence I have reported as a bug.

Would be great to instatiate dynmically unknow no. of object as array in this way.

Thanks in advance


 All   Comments   Change History      Sort Order:
Jason Carreira - [18/Feb/04 07:31 AM ]
Your property name is users (getUsers, setUsers), but your field names are user[0], user[1]...

You could also try just leaving the array index stuff off... just name all of the fields "users"... With all of them having the same name, it will get sent to the server as a String[] by the browser.

Bhavin Kamani - [18/Feb/04 11:18 PM ]
Yes it worked well...

I was using 'users[0]' and not user[0]. However, by replacing name with 'users' it works like a charm.

Thanks once again.