You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ellen Lockhart <el...@home.com> on 2001/06/08 19:39:18 UTC

Re: Question on the ActionForm design for dynamic data?

Question on the ActionForm design for dynamic data?I have scoured this list unsuccessfully for an answer, and this email seemed the best starting point so I am responding to it with the question I have:

>>From what I can tell, this only explains how to iterate over a collection to create a form with a dynamic number of rows.  What I cannot find an answer to is how does the ActionForm need to be set up to handle population with the input field values from those rows when this form is submitted?  Does it simply need a "public void setCustomerContacts(Vector customerContacts)"?  Will Struts then populate the Vector with CustomerContact objects?  Or does it need set() methods to accept Vectors of each individual column's values?

Thanks,
Ellen
  ----- Original Message ----- 
  From: Jeff Trent 
  To: struts-user@jakarta.apache.org 
  Sent: Sunday, May 20, 2001 5:11 AM
  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 
    To: struts-user@jakarta.apache.org 
    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 


Re[2]: Question on the ActionForm design for dynamic data?

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Ellen,

You are speak about indexed properties. It can be defined by two ways

 1. One method for get and set operations
  public String[] getSomeProperty() {}

 2. Two methods
  public String getProperty( int index ) {}
  public void setProperty( int index, String value ) {}

  

Friday, June 08, 2001, 9:39:18 PM, you wrote:

EL> Question on the ActionForm design for dynamic data?I have scoured this list unsuccessfully for an answer, and this email seemed the best starting point so I am responding to it with the question
EL> I have:

>>>From what I can tell, this only explains how to iterate over a collection to create a form with a dynamic number of rows.  What I cannot find an answer to is how does the ActionForm need to be set
>>up to handle population with the input field values from those rows when this form is submitted?  Does it simply need a "public void setCustomerContacts(Vector customerContacts)"?  Will Struts then
>>populate the Vector with CustomerContact objects?  Or does it need set() methods to accept Vectors of each individual column's values?

EL> Thanks,
EL> Ellen
EL>   ----- Original Message ----- 
EL>   From: Jeff Trent 
EL>   To: struts-user@jakarta.apache.org 
EL>   Sent: Sunday, May 20, 2001 5:11 AM
EL>   Subject: Re: Question on the ActionForm design for dynamic data?


EL>   (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:

EL>       public Vector getCustomerContacts()
EL>       {
EL>           CustomerContact lastCustomerContact = (CustomerContact)this.customerContacts.lastElement();
EL>           if (!lastCustomerContact.isEmpty())                                            // is this slot being used?
EL>               this.customerContacts.addElement(new CustomerContact());    // always have one available slot at the end of the matrix
              
EL>           return this.customerContacts;
EL>       }

EL>   (2) Do not use the reset() method.

EL>   (3) On your JSP, use code like this:
EL>       <% int i = 0; %>
EL>       <logic:iterate id="customerContact" name="adminUpdateProfileForm" property="customerContacts">
EL>          <tr>
EL>           <td class="smallFont"><input type='text' name="customerContact[<%= i %>].contactName" value="<%= ((com.domain.project.CustomerContact)customerContact).getContactName() %>"></td>
EL>           <td class="smallFont"><input type='text' name="customerContact[<%= i %>].contactTitle" value="<%= ((com.domain.project.CustomerContact)customerContact).getContactTitle() %>"></td>
EL>           <td class="smallFont"><input type='text' name="customerContact[<%= i %>].contactPhone" value="<%= ((com.domain.project.CustomerContact)customerContact).getContactPhone() %>"></td>
EL>          </tr>
EL>          <% i++; %>
EL>       </logic:iterate>

EL>   (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.
   
   
EL>   Hope this help,
EL>   Jeff
   
EL>     ----- Original Message ----- 
EL>     From: Joyce Tang 
EL>     To: struts-user@jakarta.apache.org 
EL>     Sent: Saturday, May 19, 2001 11:28 PM
EL>     Subject: Question on the ActionForm design for dynamic data?


EL>     Here is the situation. 

EL>     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
EL> 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
EL> 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?

EL>     Thanks a lot, 

EL>     Joyce 




-- 
Best regards,
 Oleg                            mailto:gonza@penza.net