struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@btInternet.com>
Subject RE: Problems with iterate
Date Sun, 01 Jul 2001 22:56:52 GMT
You need to do two things.

First, you need to generate appropriate names for your input fields. If you
use the current Struts tags then all the occurances of your two fields in
the example below will generate names of "firstName" and "lastName". What
you want is to generate names in the format "contactDataVector[x].firstName"
and "contactDataVector[x].lastName", where x is the index number of the
field. Dave Hay has posted a set of modified Struts tags which generate
these names on Ted Husted's site:
  http://www.husted.com/about/struts/resources.htm#extensions  - "Indexed
Tags"

Secondly you need to provide the appropriate getters/setters in your bean
and ActionForm. Obviously in your bean you need setFirstName() and
setLastName() methods - additionally you need the following getter in your
ActionForm:

  public ContactData getContactDataVector(int index) {

     return (ContactData)(contactDataVector.get(index));

  }

Hope this helps.


Niall



> -----Original Message-----
> From: Torsten Terp [mailto:torsten@terps.dk]
> Sent: 01 July 2001 19:01
> To: Struts user list
> Subject: Problems with iterate
>
>
> Hi,
>
> Sorry if this has been answered before, but i havent been able to
> find an answer!
>
> Im using iterate to display a vector containg valueobjects, i.e.,
>
> <html:form action="showContacts">
> <logic:iterate id="contacts" name="form" property="contactDataVector">
> <html:hidden name="contacts" property="contactId"/>
> <tr>
>   <td width="150">
>     <html:text name="contacts" property="firstName" size="20"/>
>   </td>
>   <td width="150">
>     <html:text name="contacts" property="lastName" size="20"/>
>   </td>
> </tr>
> ...
> ...
>
> 'form' is my struts form bean, 'contactDataVector' is a vector of
> 'contactData'
> objects each containing (among others) the variables 'firstName'
> and 'lastName'.
>
> There is no problem in displaying the data, all goes well, but
> updating fields
> in the form is not working, when i want to save the changes in
> the struts action
> the vector is null! I can see that making a variable 'firstName'
> in the form, results
> in a call to its setter method, i.e., i can make it work when
> updating a single row,
> but i cant manage to get the update to work on the actual
> contactData objects in the
> vector. ?!?!
>
> Any advices out there??
>
> ^terp
>


Mime
View raw message