Antony Paul wrote:
Hi all,
Sorry if it is a repost. Using Struts 1.1.
I have an ActionForm in which displays an array of items. I want to use
DynaValidatorForm here which uses ArrayList as property holders. I am able
to pre-populate the form. I have trouble in displaying the values and on
submission nothing is populated. If somebody can give an example it will be
very useful to me.


Struts-config.xml
------------------
<form-bean name="PriceForm"
type="org.apache.struts.validator.DynaValidatorForm">
   <form-property name="productid" type="java.util.ArrayList"/>
   <form-property name="productdesc" type="java.util.ArrayList"/>
</form-bean>

JSP
---
logic:iterate name="PriceForm" property="productid" id="pid"
indexId="index">
   <tr>
    <//html:hidden property='<%="productid["+index+"]"%>'/>
    <td><html:text property="productdesc" indexed="true"/>

    <td><//html:text property='<%="productdesc["+index+"]"%>'/>

   </tr>
   </logic:iterate>

I  tried using indexed attribute. Then HTML generated is

<input type="text" name="org.apache.struts.taglib.html.BEAN[0].productdesc"
value="[product desc 0]">

See the value is in braces.

If I use <html:text property="productdesc" indexed="true"/> I get

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

What is wrong ?.

rgds
Antony Paul

Antony - I've never done this with an arraylist myself, just arrays - but in my experience the error you are getting comes up when struts can't figure out the length of the collection you are trying to iterate over. This usually happens when the form is being put in the request scope and not in the session scope.


Is it possible you could post the relevant portions of your "loader" class, as well as the action mappings for the loader and submit forms?

The other alternative you may have is to look into using Niall's LazyList implementation. It is supposed to get rid of a lot of headache's like that. (Just google for struts lazylist and you'll see what you need.)

Matt



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to