I looked at your first message and saw the code snippet you put there. I
tried out using your jsp code and put together a couple of classes & got it
working no problem:

    <html:text property="data.rows[1].employeeName" size="30"
maxlength="30"/>

One problem I did have was I had to change the above from "EmployeeName" to
"employeeName" to get it working.

I also used the following classes:

In the Action Form:

  private TestBean data = new TestBean();
  public TestBean getData() {
    return data;
  }

I created a TestBean as follows:

  public class TestBean {
    private EmplBean[] rows = new EmplBean[] {new EmplBean("Fred"), new
EmplBean("John")};
    public EmplBean getRows(int index) {
      return rows[index];
    }
  }

I created an EmplBean as follows:

  public class EmplBean {
    public String EmployeeName;
    public EmplBean(String name) {
      EmployeeName = name;
    }
    public String getEmployeeName() {
      return EmployeeName;
    }
    public void setEmployeeName(String name) {
      EmployeeName = name;
    }
  }

> -----Original Message-----
> From: Niall Pemberton [mailto:[EMAIL PROTECTED]]
> Sent: 10 April 2001 01:03
> To: [EMAIL PROTECTED]
> Subject: RE: POSTing arrays in struts
>
>
> Yes I have it working and I'm using the beta (i.e. version 1.0-b1).
>
> Not quite sure what you mean by "one level of indirection lower" but my
> suggestion is to set the debug level in BeanUtils - which is what
> ActionServlet uses to populate the bean - it should give you a
> whole load of
> output telling you what its trying to do - unfortunately its using
> System.out.println so it'll come out to the tomcat console.
>
>       BeanUtils.setDebug(1); // its a static method
>
> Otherwise you could try posting your code here and perhaps someone will be
> able to spot whats going wrong.
>
> Niall
>
> > -----Original Message-----
> > From: Will Spies/Towers Perrin [mailto:[EMAIL PROTECTED]]
> > Sent: 09 April 2001 21:30
> > To: [EMAIL PROTECTED]
> > Cc: [EMAIL PROTECTED]
> > Subject: RE: POSTing arrays in struts
> >
> > That is my situation exactly. I've tried session scope and
> request scope.
> > For request, I did the same exact trick you have here. Both
> cases it's not
> > working for me. My ActionForm is not getting populated at all. I am one
> > level of indirection lower than what you have here but same
> > concept. If you
> > have this working though the problem could just be that I'm messing up
> > somewhere and one of my properties is coming back null. I
> didn't think so
> > though. What build are you using?
> >
> >                                                   To:
> > <[EMAIL PROTECTED]>
> >                     "Niall Pemberton"             cc:     (bcc:
> > Will Spies/Towers Perrin)
> >                     <niall.pemberton@btInt        Subject:
> > RE: POSTing arrays in struts
> >                     ernet.com>
> >
> >
> >
> > I don't know if I understand your situation but is this a scope issue?
> > Either you use session scope and set up your beanArray before
> showing the
> > form, then when a POST is done Struts will call the appropriate
> setters on
> > the beans in the array. Or you use request scope which is a bit
> > more tricky
> > because the bean array is empty so Struts can't call the
> setters. In this
> > case I got round this by generating beans as the setters were
> > being called:
> >
> > In my ActionForm class:
> >
> >   private Vector beanVector;
> >
> >   public MyBean getBeanVector(int index) {
> >     if (beanVector == null)
> >       beanVector = new Vector(15, 5);
> >
> >     if (index+1 > beanVector.size()) {
> >       for (int i = beanVector.size(); i < index+1; i++) {
> >           beanVector.add(new MyBean());
> >       }
> >     }
> >
> >     return (MyBean)beanVector.get(index);
> >   }
> >
> >
> > Thus Struts tags:
> >      <logic:iterate id="list" name="myForm" property="beanVector">
> >         <tr><td><html:text name="list" property="desc"/></td>
> >      </logic:iterate>
> >
> > generates:
> >      <input type="text" name="beanVector[0].desc" value="abc"/>
> >      <input type="text" name="beanVector[1].desc" value="def"/>
> >      <input type="text" name="beanVector[2].desc" value="ghi"/>
> >
> > Causing Struts to generate the following method call to
> populate your bean
> > array in your ActionForm:
> >            getBeanVector(0).setDesc("abc");
> >            getBeanVector(1).setDesc("def");
> >            getBeanVector(2).setDesc("ghi");
> >
> >
> >
> > > -----Original Message-----
> > > From: Will Spies/Towers Perrin [mailto:[EMAIL PROTECTED]]
> > > Sent: 09 April 2001 20:37
> > > To: [EMAIL PROTECTED]
> > > Cc: [EMAIL PROTECTED]
> > > Subject: RE: POSTing arrays in struts
> > >
> > >
> > > 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>
> > >
> > > 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>
> > > >
> > > >
> > > >
> > > > 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