Thanks for your reply. I did see these messages and I'm ok with fixing the
iterate tag issue. I have a bigger (related) problem.  My problem is when I
get a POST struts does not fill in my ActionForm correctly. For example, in
your example my LoginForm would not contain a beanArray with 3 elements. It
would contain 0. Struts is failing to generate the proper getter calls as
far as I can tell.






                                                                                       
                                     
                                                                                       
                                     
                                                  To:     
<[EMAIL PROTECTED]>                                  
                    "Niall Pemberton"             cc:     (bcc: Will Spies/Towers 
Perrin)                                   
                    <niall.pemberton@btInt        Subject:     RE: POSTing arrays in 
struts                                 
                    ernet.com>                                                         
                                     
                                                                                       
                                     
                    04/09/01 03:05 PM                                                  
                                     
                    Please respond to                                                  
                                     
                    struts-user                                                        
                                     
                                                                                       
                                     
                                                                                       
                                     



This issue has come up quite regularly in the list. I got round this by
taking my own copies of struts tags and modifying them so that they check
if
they are contained in an "IterateTag". If they are then I generate the name
appropriately using the property from the IterateTag, the current index
value and the property from the actual tag. Struts then automatically
populates the data back appropriately. You have to do something a bit more
complex if your using request rather than session scope to generate a bean
collection but thats the only issue.

For Example:
    <logic:iterate id="list" name="formExample" property="beanArray">
       <tr><td><html:text name="list" property="desc"/></td>
    </logic:iterate>

generates:
    <input type="text" name="beanArray[0].desc" value=".."/>
    <input type="text" name="beanArray[1].desc" value=".."/>
    <input type="text" name="beanArray[2].desc" value=".."/> etc. etc.

With my modified <iterate> and <text> (& BaseFieldTag) tags. This then
causes Struts to generate appropriate method calls to populate the values
back to the form [e.g. formExample.getBeanArray(0).setCode(..) etc.]

I detailed this a couple of times as a request but unfortunately so far no
one has given any feedback. Even if this proposal is no accepted then
putting the logic to generate the "name" attribute in separate methods
which
could be overriden rather than copying the tag and having to change the
doStartTag() method would be really useful.

Previous messages:
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg05231.html
http://www.mail-archive.com/struts-dev@jakarta.apache.org/msg00975.html

Niall

P.S> I also have a similar issue where I want to overide the default
behaviour for setting the "value" attribute for another issue.

> -----Original Message-----
> From: Will Spies/Towers Perrin [mailto:[EMAIL PROTECTED]]
> Sent: 09 April 2001 16:13
> To: [EMAIL PROTECTED]
> Cc: '[EMAIL PROTECTED]'
> Subject: RE: POSTing arrays in struts
>
> I don't really understand why I have to do this. That's a lot of code to
> write too. The JSP code that I have below actually works on the read.
> Struts handles it fine and I see the actual data sitting in the input
> control when the form comes up in my browser. If struts can do that, I
> can't see why struts can't go the other way and match it up on a
> post so my
> "form' already has the data way before the 'perform' method is called.
>
>
>                                          To:
> "'[EMAIL PROTECTED]'"
>                     "Taylor,
> <[EMAIL PROTECTED]>
>                     Jeremy"              cc:     (bcc: Will
> Spies/Towers Perrin)
>                     <jtaylor@lehm        Subject:     RE: POSTing
> arrays in struts
>                     an.COM>
>
>
>
>                     04/09/01
>
>                     11:04 AM
>
>                     Please
>
>                     respond to
>
>                     struts-user
>
>
>
>
>
>
>
>
> If all your input fields have the same name then when the form is
> submitted
> there will be a
>
> in your Action class there will be a method "perform" has takes a
> parameter
> HttpServletRequest request,
>
> so, rather than doing
> PropertyUtils.copyProperties(user, form);
>
> do something like
>
> String[] rows = request.getParameterValues("InputFieldName");
> form.setRows(rows);
>
>
> > -----Original Message-----
> > From:         Will Spies/Towers Perrin [SMTP:[EMAIL PROTECTED]]
> > Sent:         09 April 2001 15:41
> > To:           [EMAIL PROTECTED]
> > Cc:           '[EMAIL PROTECTED]'
> > Subject:           RE: POSTing arrays in struts
> >
> >
> >
> > Ok. Now we are talking.
> >
> > Q1: My save action class DOES work like the example. It gets
> the form and
> > expects the ActionServlet to fill it up. By the time I get the form,
the
> > ActionServlet is done with it? How would I change this to work properly
> or
> > do I need a new version of the util class?
> >
> > Q2: I was under the impression the html:text tags did not work properly
> > inside an iterate tag.
> >
> >
> >
> >
> >
> >
> >
> >                                          To:
> > "'[EMAIL PROTECTED]'"
> >                     "Taylor,
> <[EMAIL PROTECTED]>
> >
> >                     Jeremy"              cc:     (bcc: Will
Spies/Towers
> > Perrin)
> >                     <jtaylor@lehm        Subject:     RE: POSTing
arrays
> > in struts
> >                     an.COM>
> >
> >
> >
> >                     04/09/01
> >
> >                     10:32 AM
> >
> >                     Please
> >
> >                     respond to
> >
> >                     struts-user
> >
> >
> >
> >
> >
> >
> >
> >
> > You don't need to generate index properties for the input tags.
> > Also, how does your save action class work? If you based it on
> the struts
> > examples you'll need to
> > change it because the util class that copies bean properties won't work
> > with
> > the array of values for the rows property.
> >
> > > -----Original Message-----
> > > From:         Will Spies/Towers Perrin [SMTP:[EMAIL PROTECTED]]
> > > Sent:         09 April 2001 15:13
> > > To:           [EMAIL PROTECTED]
> > > Cc:           '[EMAIL PROTECTED]'
> > > Subject:           RE: POSTing arrays in struts
> > >
> > >
> > >
> > > 1. The iterate tag does not generate index properties for the
> html_text
> > > *input* tag
> > > 2. The html:text IS in input tag!
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >                                          To:
> > > "'[EMAIL PROTECTED]'"
> > >                     "Taylor,
> > <[EMAIL PROTECTED]>
> > >
> > >                     Jeremy"              cc:     (bcc: Will
> Spies/Towers
> > > Perrin)
> > >                     <jtaylor@lehm        Subject:     RE: POSTing
> arrays
> > > in struts
> > >                     an.COM>
> > >
> > >
> > >
> > >                     04/09/01
> > >
> > >                     10:08 AM
> > >
> > >                     Please
> > >
> > >                     respond to
> > >
> > >                     struts-user
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > 1. use the iterate tag to iterate through the rows property
> > > 2. nothing happens on post because you have no input tags
> > >
> > > > -----Original Message-----
> > > > From:         Will Spies/Towers Perrin [SMTP:[EMAIL PROTECTED]]
> > > > Sent:         09 April 2001 14:35
> > > > To:           [EMAIL PROTECTED]
> > > > Subject:           POSTing arrays in struts
> > > >
> > > >
> > > >
> > > > I've read a couple archived notes on this topic and it's not
helping
> > me
> > > so
> > > > here goes.
> > > >
> > > > I'm trying to post an array of data from my view (JSP) into my
bean.
> > I'm
> > > > having great difficulty. Here is a JSP snipet of what I'm doing:
> > > >
> > > > <html:form action="/saveEmployees">
> > > > <table>
> > > >   <tr>
> > > >     <td align="left">
> > > >       <html:text property="data.rows[1].EmployeeName" size="30"
> > > maxlength
> > > > ="30"/>
> > > >     </td>
> > > >   </tr>
> > > >   <td align="right">
> > > >    <html:submit>
> > > >        <bean:message key="button.save"/>
> > > >    </html:submit>
> > > >   </td>
> > > >   <td align="left">
> > > >     <html:reset>
> > > >         <bean:message key="button.reset"/>
> > > >     </html:reset>
> > > >     &nbsp;
> > > >     <html:cancel>
> > > >       <bean:message key="button.cancel"/>
> > > >     </html:cancel>
> > > >     </td>
> > > > </table>
> > > > </html:form>
> > > >
> > > > My form consists of a getData().getRows().EmployeeName. The Rows is
> > the
> > > > array. I've added the appropriate getRows(int index) and
setRows(int
> > > > index,
> > > > ...). Still, it doesn't work. Upon the post I do not see my getters
> > > being
> > > > called and I get no data in my corresponding form. Help???
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
>
>
>
>
>





Reply via email to