Title: Question on the ActionForm design for dynamic data?
I have been struggling with this problem for a while.
 
I used the way Jeff recommended and made the application working, however, because I am not using the struts taglib displaying the collection data, there is no sense to put that collection in the form.  So I do validation and populating the session data in the action.  I don't like that.  I am pretty much sure there should be a way to use nested form in struts.  So that I can use something like following to display the contributors:
  <logic:iterate id="contributors" name="plan" property="contributors">
  <td><html:text property="<%= \"contributors[\" + i\"].percentage\" %>"/></td>    <td>
</logic:iterate>
I tried couple of ways.  No one works so far.
 
One of the approaches I tried is to have the a PlanForm and a ContributorForm.  And one of the properties/fields in PlanForm is ContributorForm[]. I think it is a way to do it.  But I don't know how.
 
Can someone point me to some solution.  I really appreciate.
 
Joyce
-----Original Message-----
From: Joyce Tang [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 23, 2001 12:05 AM
To: [EMAIL PROTECTED]
Subject: RE: Question on the ActionForm design for dynamic data?

Why should not the reset() be used?  Isn't it called automatically, anyways?  Such as when the validation of the form fails?
-----Original Message-----
From: Jeff Trent [mailto:[EMAIL PROTECTED]]
Sent: Sunday, May 20, 2001 6:12 AM
To: [EMAIL PROTECTED]
Subject: Re: Question on the ActionForm design for dynamic data?

(1) Have a Vector / Collection of contributors (ie. getContributors()) belonging to your form.  Inside that function, check to see if you need more rows by using code similar to the following:
 
    public Vector getCustomerContacts()
    {
        CustomerContact lastCustomerContact = (CustomerContact)this.customerContacts.lastElement();
        if (!lastCustomerContact.isEmpty())                                            // is this slot being used?
            this.customerContacts.addElement(new CustomerContact());    // always have one available slot at the end of the matrix
            
        return this.customerContacts;
    }
(2) Do not use the reset() method.
 
(3) On your JSP, use code like this:
    <% int i = 0; %>
    <logic:iterate id="customerContact" name="adminUpdateProfileForm" property="customerContacts">
       <tr>
        <td class="smallFont"><input type='text' name="customerContact[<%= i %>].contactName" value="<%= ((com.domain.project.CustomerContact)customerContact).getContactName() %>"></td>
        <td class="smallFont"><input type='text' name="customerContact[<%= i %>].contactTitle" value="<%= ((com.domain.project.CustomerContact)customerContact).getContactTitle() %>"></td>
        <td class="smallFont"><input type='text' name="customerContact[<%= i %>].contactPhone" value="<%= ((com.domain.project.CustomerContact)customerContact).getContactPhone() %>"></td>
       </tr>
       <% i++; %>
    </logic:iterate>
(4) Have a button on the form "Add more rows" in which case the form posts to itself and will cause a new row to be added at the bottom of the grid.
 
 
Hope this help,
Jeff
 
----- Original Message -----
From: Joyce Tang
Sent: Saturday, May 19, 2001 11:28 PM
Subject: Question on the ActionForm design for dynamic data?

Here is the situation.

I am developing a system to maintain a contribution plan.  I need to input the plan information first and add unlimited number of contributors, specifying each share of the plan.  So there will be a page with contribution plan information and a list of all the contributors.  The information you can edit on this page is the percentage of share of each contributor. Validation rules are: share need to add up to 100 and share figure is an integer between 0 and 100.   Since the number of contributors is unknown in advance, how should I design the ActionForm?

Thanks a lot,

Joyce

Reply via email to