I'd like to update mass user Data in a form with a dynamic number of rows
(depending on the number of users already available).

I use a dynaform:
<form-bean
    name="userForm"
    type="org.apache.struts.action.DynaActionForm">
    <form-property
        name="id"
        type="java.lang.String[]" />
    <form-property
        name="username"
        type="java.lang.String[]" />
</form-bean>

Now I use a MappingDispatchAction "UserAction" with two methods:
public ActionForward prepareUpdate(...) {
    // static implementation for testing only
    // once it works I'll get the existing objects from a DAO object here
    DynaActionForm userForm = (DynaActionForm) form;
    userForm.set("id", 0, "0");
    userForm.set("username", 0, "user0");
    userForm.set("id", 1, "1");
    userForm.set("username", 1, "user1");
    return mapping.findForward("success");
}

and...

public ActionForward update(...) {
    DynaActionForm userForm = (DynaActionForm) form;
    // Later on: Update data using DAO object ...
    return mapping.findForward("success");
}

The form looks as follows:
<form action="/UserUpdate">
<logic:iterate id="_username" name="userForm" property="username"
indexId="idx">
   <html:hidden property='<%= "id[" + idx + "]" %>' /><br/>
   <html:text property='<%= "username[" + idx + "]" %>' /><br/>
</logic:iterate>
<html:submit />
</form>

struts-config.xml action config looks like this:
<action
   path="/PrepareUserUpdate"
   type="my.actions.UserAction"
   parameter="prepareUpdate"
   name="userForm"
   validate="false"
   scope="request">
   <forward name="success"
       path="/UserUpdateForm.do" />
</action>
<action
   path="/UserUpdateForm"
   forward="/WEB-INF/pages/UserUpdateForm.jsp" />
<action
   path="/UserUpdate"
   type="my.actions.UserAction"
   parameter="update"
   name="userForm"
   validate="false"
   scope="request">
   <forward name="success"
       path="/MySuccessPage.do" />
</action>

My problems:
1. Execution fails when populating the DynaActionForm indexed properties
within prepareUpdate(...) with a IndexOutOfBoundsException. I'm aware of the
size-attribute of the form-property tag but the size is unknown at first.
2. Is my idea how to do it basically right and working somehow? Or are there
better ways to do that? Maybe nested properties? (didn't get them to work
either)
3. Is it a good idea to use DynForms here?

Thanks for your help,
Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to