I completely agree with you about how HTTP handles requestparameter. If this is the only solution, then I will have to do some reengineering work in my porblem area to deal with ordering. :-(
This is really annoying. I can't imagine I am the first person with this problem. I don;t really see the problem with Struts handling this issue. At form creation/instantiation time by Struts framwork, you always know the amount of indexed parameters. You just count them! :-) So, you the size of the array to be created. The only thing left to do is to put the elements in their proper order. Example: RequestString on submit ..... someWrapper[0].name=blabla1&someWrapper[1].name=blabla2&someWrapper[2].name=blabla3...... Voila, you have created a array of size 3, because there three occurrences of indexed property "someWrapper[x].name". Kind Regards, Urso -----Oorspronkelijk bericht----- Van: Niall Pemberton [mailto:[EMAIL PROTECTED] Verzonden: donderdag 7 december 2006 14:16 Aan: Struts Users Mailing List Onderwerp: Re: Struts1: Indexed Properties, BeanUtils populate, Form on REQUEST scope On 12/7/06, Urso Wieske <[EMAIL PROTECTED]> wrote: > Hi Niall, > > Thanks for the reply! Apparantly this problem is quite difficult to get > answer upon. You're the only one until now. > > Well, I was getting different exception in different scenario. > - When I put an array initialization (someWrappers = )in myForm's default > constructor, I would get Array Out Of Bound exceptions. > - When I don't do an array initialization for myForm (on REQUEST scope), I > would get a method invocation exception from BeanUtils.poulate() due to some > getter property descriptor that can't be found. (?) But I have declared all > my getters and setters (see fot your self below). > > I checked my generated HTML sources (from JSP), but they are all rendered as > expected. That is, like you have specified below. > Weird, huh? > > When I chang my scope to session... it seems to work. But I don't want my > form in sessin scope. (And if this is working indeed in session scope.... why > not for requests scope?) > > The solution that you propose... I have seen it too on the internet. But this > solution does not guarantee the right order of the array elements. And order > IS a Requirement for my problem area. You can't control which order http sends the request parameters in - but theres no reason why you can't just "grow" your array to cope with whatever size the indexed getter is asking for. public SomeWrapper getSomeWrapper(int index) { if (wrappers == null) { wrappers = new SomeWrapper[index + 1]; } // Grow the array if (wrappers.length < index + 1) { newWrappers = new SomeWrapper[index + 1]; System.arraycopy(wrappers, 0, newWrappers, 0, wrappers.length); wrappers = newWrappers; } if (wrappers[index] == null) { wrappers[index] = new SomeWrapper(); } return wrappers[index]; } LazyDynaBeans do this for you: http://struts.apache.org/1.x/userGuide/building_controller.html#lazy_action_form_classes Also more info on "lazy" index growth is here on the wiki: http://wiki.apache.org/struts/StrutsCatalogLazyList Niall > Any hints? > > > Kind regards, > > Urso Wieske > > > > -----Oorspronkelijk bericht----- > Van: Niall Pemberton [mailto:[EMAIL PROTECTED] > Verzonden: donderdag 7 december 2006 9:40 > Aan: Struts Users Mailing List > Onderwerp: Re: Struts1: Indexed Properties, BeanUtils populate, Form on > REQUEST scope > > > So what BeanUtils exception are you getting? > > Your jsp should be generating the following? > <input type=".." name="someWrapper[0].propA" ...> > <input type=".." name="someWrapper[1].propA" ...> > > BeanUtils will try and access the indexed getter - getSomeWrapper(0) > and then call setPropA(...) - presumably its one of these methods ist > having problems with? > > Anyway the problem usually with request scope beans is that when it > calls the getSomeWrapper(index) method the array isn't initialized and > it returns null - if you put logic to "automatically" grow your array > in the getSomeWrapper(index) method then it should solve this. > > Niall > > On 12/6/06, Urso Wieske <[EMAIL PROTECTED]> wrote: > > Hi folks, > > > > I have problem with the scenario "Indexed Properties, BeanUtils and Form on > > REQUEST scope". > > When I select a a value from (1 or 2) from the dropdownlist and submit the > > form, I get an exception from BeanUtils.populate method about some getter > > which can be found!?? > > IF change the scope of myForm to Session in my struts configuration, then I > > don't have a problem with beanutils. But I want my form on request scope! > > > > I have described below my problem scenario. > > > > Is there a solution to this problem?? (form on request scope) > > I have looked in diffenrent aspects but I am not sure what is happening > > here with BeanUtils: > > - commons BeanUtil JAR version issue? > > - scope (request/session) issue? > > - JRE/Beanutil issue? > > - program issue of in my scenario? > > - array issue? > > > > > > Thanks > > Urso Wieske > > > > > > Scenario abstraction of my problem: > > 1.PrepareAction/myForm --------{forward}--------> 2.viewJSP > > -----{submit}-------> 3.ProcessAction/myForm > > > > > > Action Mapping Configuration relevant settings: > > 1) myForm (MyForm class) is on request scope > > 3) myForm(MyForm class) is on request scope > > > > > > MyForm considerations: > > I have a property "someWrappers" of type array of SomeWrapper (thus, not a > > List type!) > > properties: > > - SomeWrapper [] getSomeWrappers() { return someWrappers;} > > - void getSomeWrappers(SomeWrapper [] someWrapper) {this.someWrappers = > > someWrapper;} > > - SomeWrapper getSomeWrapper(int index) {return someWrappers[index];} > > - void setSomeWrapper(int index, SomeWrapper someWrapper) > > {this.someWrappers[index] = someWrapper;} > > > > I have changed the name of the indexed property from plural to single noun > > (someWrapper,... to bypass the JRE1.3/1.4 - JavaBeans specs - BeanUtils > > issue. > > My Target runtime is JRE5. > > > > viewJSP is a JSP file which has the following structure: > > > > <html:form action="/someAction"> > > ..... > > <logic:notEmpty name="myForm" property="someWrappers" > > > <logic:iterate property="someWrappers" id="someWrapper" > > > <html:select name="someWrapper" property="propA" > > indexed="true"> > > <html:option value="1">1</html:option> > > <html:option value="2">2</html:option> > > </html:select> > > <logic:iterate> > > </logic:notEmpty> > > > > ..... > > </html:form> > > > > > > > > > > > > --------------------------------------------------------------------- > 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] > > --------------------------------------------------------------------- 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]