I got a doubt whether it is possible to have attributes of custom type in the form bean. The custom type will be composed itself of two or more attributes. I am trying to understand whether the population of data into such kind of beans is possible in the existing Struts, without using custom request processor.
My other doubt is can we can have arrays of objects in the form bean. I have tried this and was successful, if I am submitting the data directly form multiple-selection allowed dropdown. I am trying to understand whether it is possible with the use of hidden fields by giving names such as "person", "person", and so.
Thanks in advance
Cheers,<br />Hemanth...<br />(When opportunity doesn't knock, build a door.)
The other issue which is that, for "indexed references", we need to instantiate the array in the form bean by giving the size at the compile time itself. Is there an approach so that, we can make that dynamic.
Thanks in advance. [ March 14, 2005: Message edited by: Hemanth Pallavajula ]
Joined: Feb 15, 2005
When trying to figure out what Struts will do with an <html:xxxx> tag, a helpful exercise is to write out the method calls that struts will make when the submit button is pressed. Based on the link I gave you in my previous post, here is a method call that will be made by struts when your form is submitted:
If scriptDataBean is in request scope, when Struts tries to populate the bean, the componentIds array in scriptDataBean will contain 20 elements, each of them null. When struts calls getComponentIds(0), a null value will be returned. When it tries to execute setKey("14207") on a null value, a null pointer exception will be thrown.
One possible solution to this would be to add a reset() method to your form bean that places an instance of KeyValuePair in each of the 20 array elements. The reset() method is called by struts before trying to populate the form bean. See the documentation for the correct signature for this method.
Another possible solution would be to modify the getComponentIds() method so that it checks to see if the element is null, and if so instantiates a new KeyValuePair, places it in the array, and returns it.
In answer to your second question about how to make the size of your array dynamic, you could use one of the List classes (e. g. ArrayList) in the java.util package instead of an array. [ March 14, 2005: Message edited by: Merrill Higginson ]