In the commons-collections use ListUtils.LazyList to initialize a list in the bean.
Brandon Goodin Phase Web and Multimedia PO Box 85 Whitefish MT 59937 P (406) 862-2245 F (406) 862-0354 [EMAIL PROTECTED] http://www.phase.ws -----Original Message----- From: Richard Kooijman [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 25, 2003 1:56 PM To: [EMAIL PROTECTED] Subject: Indexed property problem Hello, I have a problem setting form properties that have a type of String[]. I have seen similar problems in other messages that came around, but now of them or their answers seem to address the specfic issue we encountered. Somewhere in Struts (see stack trace below) the Array.set() method tries to fill in the String array using the indices from the form parameters of the submit request. The array that that method uses or gets passed has not been allocated to be able to hold the number of parameters we tries to pass on. In fact it is of String[0]. Somehow you would expect that either Struts of the DynaActionForm beans should make an extra step and pre-allocate the array before setting the individual array elements. This does not seem to be done. My questions are: - do we use the feature in the wrong manner? - do we need to specify that array size somewhere, with which Struts can pre-allocate the array? - did we stumble on a bug? Any input appreciated, Richard Kooijman Here follows some details on this issue: I have this defined in my struts-config.xml: <form-bean dynamic="true" name="soortopvanglocatieForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="vorm" type="java.lang.String" /> <form-property name="voorkeurenKinderdagverblijfVoorkeur" type="java.lang.String[]" /> <form-property name="voorkeurenBuitenschoolseopvangVoorkeur" type="java.lang.String" /> <form-property name="voorkeurenBuitenschoolseopvangBasisschool" type="java.lang.String" /> <form-property name="voorkeurenHalvedagopvangVoorkeur" type="java.lang.String" /> </form-bean> Note the array of String as the type of voorkeurenKinderdagverblijfVoorkeur. In my .jsp I have this: <logic:iterate id="voorkeur" name="soortopvanglocatieForm" property="voorkeurenKinderdagverblijfVoorkeur" indexId="i"> <html:text name="soortopvanglocatieForm" property='<%="voorkeurenKinderdagverblijfVoorkeur[" + i + "]"%>' size="20"/> </logic:iterate> What happens is that the initial display of the page looks just fine. Things start to get messy when I essentially try to add or delete a html:text field (by trying to change the array of voorkeurenKinderdagverblijfVoorkeur in the background). When I hit one of the two buttons I defined, Struts start parsing the POST information but halts in the bean populate() section: java.lang.ArrayIndexOutOfBoundsException at java.lang.reflect.Array.set(Native Method) at org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:457) at org.apache.commons.beanutils.PropertyUtils.setIndexedProperty(PropertyUtils. java:1414) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1013) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1097) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.j ava:798) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1422) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:523) I debugged this in the source and the array that is to be set by Array.set is of type String[0]. And the particular instance that is being set is at index 1. Anyway, it seems that the array properties in the DynaValidatorForm we are using aren't being allocated. Any ideas or hints? We use Struts 1.1b3, bean-utils 1.6.1. Regards, Richard. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]