You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sa...@lntinfotech.com on 2001/07/11 17:08:30 UTC
Updation using iterate tag
Hi All,
I have one form bean namely "MyFormBean".
This bean contain vector (pricesVector) of class type "Price".
The class Price has two attribute "oldPrice" and "newPrice"
I want to display prices vector in such fashion
---------------------------------------------------------------------
oldprice1 (as label) newPrice1 (in text box)
oldprice2 (as label) newPrice2 (in text box)
oldprice2 (as label) newPrice2 (in text box)
---------------------------------------------------------------------
How do I do this using iterate tag, so that any updation in text box should
get updated in the vector (prices)?
I tried using iterate tag but could not get through?
Anybody having solution for this.
best regards,
Sandeep
Re: Updation using iterate tag
Posted by Gregor Rayman <gr...@gmx.net>.
<Sa...@lntinfotech.com> wrote:
> Hi All,
>
> I have one form bean namely "MyFormBean".
> This bean contain vector (pricesVector) of class type "Price".
>
> The class Price has two attribute "oldPrice" and "newPrice"
>
> I want to display prices vector in such fashion
>
> ---------------------------------------------------------------------
> oldprice1 (as label) newPrice1 (in text box)
> oldprice2 (as label) newPrice2 (in text box)
> oldprice2 (as label) newPrice2 (in text box)
> ---------------------------------------------------------------------
>
> How do I do this using iterate tag, so that any updation in text box should
> get updated in the vector (prices)?
> I tried using iterate tag but could not get through?
>
> Anybody having solution for this.
1) You have to have two properties in your ActionForm:
public Collection getPrices();
and
public Price getPrice(int i);
Note: getPrice() should return valid Price even if the Vector does not
contain it.
it could look something like this:
public Price getPrice(int i) {
while (pricesVector.size() <= i) {
pricesVector.add(new Price());
}
return pricesVector.get(i);
}
2)
your iterate tag could look something like this:
<logic:iterate
name="editPricesForm" property="prices"
id="element" indexId="i"
type="Price">
<tr>
<td><bean:write name="element" property="oldPrice" /></td>
<td><html:text property='<%= "price[" + i + "].newPrice" %>' />
<html:hidden property='<%= "price[" + i + "].productID" %>' />
</td>
</tr>
</logic:iterate>
You have to know, that the Vector will be FILLED (not just updated) when the
form is submitted.
--
gR
Long Story short
Posted by Frank Ling <fe...@hotmail.com>.
Hi, There:
I send a long version story regarding for the Iteration tag with indexed tag
for property update. Not too much people response. Here is the short version
for that story.
I get Dave hay's indexed tag work good with the Iterate tag for showing the
text field of my array attributes. I get attributes[n].value shows properly
on my JSP page. but nothing setting back to attributes array of my form
bean. the whole array is null after I received it on the next action class.
Can anybody explain to me, why I get all these attributes[n].value shows as
the name of HTML text name, then that will automatically populate back to my
array? It's not working that way for me right now. what I did wrong. Any
suggestion will be highly appreciated.
Thanks
Best Regards
Frank Ling