You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vaibhav Patil <V....@zensar.com> on 2001/07/09 14:02:33 UTC

Iterate tag update

Hi,
    I am using logic:iterate tag as follows to print a table with text
boxes. 

        <logic:iterate id="product" name="productSearchForm"
property="productList">
        <tr>
          <td align="left">
            <bean:write name="product" property="productNumber"
filter="true"/>
          </td>
          <td align="center">
            <html:text name="product" property="quantity" size="3"/>
          </td>
        </tr>
        </logic:iterate>

I have a array of objets(Product) in productList. When I update the quantity
and submit the page, it does not update the information into the
productList.
    What might be the problem???

Vaibhav


Re: Iterate tag update

Posted by suhas <su...@techmas.hcltech.com>.
Do u have setter methods in the Product class  like - setQuantity(int qty)
???
 Also U need to have indexed iterate tag written by Dave Hey . So u can use

<html:text name="product" property="quantity" size="3"  index= "true"/>
Here is the ActionForm

public Product [ ] getProductList( ) {
    return this.productList;
}
public setProductList(Product [ ] productList) {
    this.productList = productList ;
}

public Product getProductList(int index) {
    return  (Product)productList[index];
}

Remember have proper setter methods in the Product class like setQuantity
 int qty )

Suahs

----- Original Message -----
From: Vaibhav Patil <V....@zensar.com>
To: <st...@jakarta.apache.org>
Sent: Monday, July 09, 2001 1:02 PM
Subject: Iterate tag update


> Hi,
>     I am using logic:iterate tag as follows to print a table with text
> boxes.
>
>         <logic:iterate id="product" name="productSearchForm"
> property="productList">
>         <tr>
>           <td align="left">
>             <bean:write name="product" property="productNumber"
> filter="true"/>
>           </td>
>           <td align="center">
>             <html:text name="product" property="quantity" size="3"/>
>           </td>
>         </tr>
>         </logic:iterate>
>
> I have a array of objets(Product) in productList. When I update the
quantity
> and submit the page, it does not update the information into the
> productList.
>     What might be the problem???
>
> Vaibhav


Re: Iterate tag update / expalin/why what form bean!!

Posted by Chuck Amadi <ch...@breconbeacons.org>.
Hi, i am currently reading up on delegating as much processing as possible to
javabeans components hence i have come across various beans regarding html forms
ie <html:select,html:option, logic:iterate etc etc . Pls could anyone explain or
advise were one can get an understanding on selection to the desired form bean.
Cheers chuck

Gregor Rayman wrote:

> The problem is, the generated names of the HTML form elements do not
> correspond to the names of properties of your ActionForm.
>
> Here a sample, how this can be done:
>
>   <logic:iterate name="myForm" property="elements" id="element" indexId="i"
>      type="de.grayman.test.struts.MyElement">
>     <tr>
>       <td>
>         <html:checkbox property='<%= "element[" + i + "].member" %>'  />
>         <html:hidden property='<%= "element[" + i + "].elementName" %>'  />
>       </td>
>       <td><bean:write name="element" property="elementName" /></td>
>       <td><bean:write name="element" property="elementDescription" /></td>
>     </tr>
>   </logic:iterate>
>
> In the MyForm class, there have to be two properties (getter methods):
>
> 1) the collection "elements"
> 2) indexed property "element"
>
> private Vector elements;
>
> public Collection getElements() {
>     return this.elements;
> }
>
> public MyElement getElement(int i) {
>    while (getGroups().size() <= i) {
>        this.element.add(new MyElement());
>    }
>    return (MyElement) this.elements.get(i);
> }
>
> Note: Class MyElement has read/write properties member, elementName,
> elementDescription, ...
>
> Note: The getElement(int i) fills the Vector with empty elements, if they do
> not exist.
> In this way, the form will be filled correcly from the submitted HTML-Form. Of
> course,
> you could use another approach, e.h. HashTable or an Array instead of Vector.
>
> --
> gR
>
> ----- Original Message -----
> From: "Vaibhav Patil" <V....@zensar.com>
> To: <st...@jakarta.apache.org>
> Sent: Monday, July 09, 2001 2:02 PM
> Subject: Iterate tag update
>
> > Hi,
> >     I am using logic:iterate tag as follows to print a table with text
> > boxes.
> >
> >         <logic:iterate id="product" name="productSearchForm"
> > property="productList">
> >         <tr>
> >           <td align="left">
> >             <bean:write name="product" property="productNumber"
> > filter="true"/>
> >           </td>
> >           <td align="center">
> >             <html:text name="product" property="quantity" size="3"/>
> >           </td>
> >         </tr>
> >         </logic:iterate>
> >
> > I have a array of objets(Product) in productList. When I update the quantity
> > and submit the page, it does not update the information into the
> > productList.
> >     What might be the problem???
> >
> > Vaibhav
> >

--
The views expressed by the sender of this message don't
necessarily represent those of Brecon Beacons National Park
Authority. This message is intended for the addressee(s) only
and is sent in confidence; if you receive it in error, please can you
let us know (at it@breconbeacons.org) and then destroy all copies.
Nid yw'r farn a fynegir gan anfonwr y neges hon o anghenraid yn
adlewyrchu barn Awdurdod Parc Cenedlaethol Bannau Brycheiniog.
Neges yw hon a fwriadwyd ar gyfer y derbynnydd/derbynyddion
yn unig ac fe'i hanfonir yn gyfrinachol; os ydych yn ei dderbyn
mewn camgymeriad, a fyddech gystal â rhoi gwybod i
ni (yn it@breconbeacons.org) ac yna dilëwch bob copi.



Re: Iterate tag update

Posted by Gregor Rayman <gr...@gmx.net>.
The problem is, the generated names of the HTML form elements do not
correspond to the names of properties of your ActionForm.

Here a sample, how this can be done:

  <logic:iterate name="myForm" property="elements" id="element" indexId="i"
     type="de.grayman.test.struts.MyElement">
    <tr>
      <td>
        <html:checkbox property='<%= "element[" + i + "].member" %>'  />
        <html:hidden property='<%= "element[" + i + "].elementName" %>'  />
      </td>
      <td><bean:write name="element" property="elementName" /></td>
      <td><bean:write name="element" property="elementDescription" /></td>
    </tr>
  </logic:iterate>


In the MyForm class, there have to be two properties (getter methods):

1) the collection "elements"
2) indexed property "element"

private Vector elements;

public Collection getElements() {
    return this.elements;
}

public MyElement getElement(int i) {
   while (getGroups().size() <= i) {
       this.element.add(new MyElement());
   }
   return (MyElement) this.elements.get(i);
}


Note: Class MyElement has read/write properties member, elementName,
elementDescription, ...

Note: The getElement(int i) fills the Vector with empty elements, if they do
not exist.
In this way, the form will be filled correcly from the submitted HTML-Form. Of
course,
you could use another approach, e.h. HashTable or an Array instead of Vector.

--
gR


----- Original Message -----
From: "Vaibhav Patil" <V....@zensar.com>
To: <st...@jakarta.apache.org>
Sent: Monday, July 09, 2001 2:02 PM
Subject: Iterate tag update


> Hi,
>     I am using logic:iterate tag as follows to print a table with text
> boxes.
>
>         <logic:iterate id="product" name="productSearchForm"
> property="productList">
>         <tr>
>           <td align="left">
>             <bean:write name="product" property="productNumber"
> filter="true"/>
>           </td>
>           <td align="center">
>             <html:text name="product" property="quantity" size="3"/>
>           </td>
>         </tr>
>         </logic:iterate>
>
> I have a array of objets(Product) in productList. When I update the quantity
> and submit the page, it does not update the information into the
> productList.
>     What might be the problem???
>
> Vaibhav
>