I'm using Struts and I'm trying to create some dynamic html:select dropdown lists. I say dynamic because these "select" controls should be rendered based on an arraylist of objects that is created in an action that setups the form. If this ArrayList contains two objects, then two html:select should be created, if contains three, then three are created and so on...
Since I don't know how many objects the ArrayList contains at runtime, I supposed that I needed something dynamic, since I need the selected value of each select list in the action that gets called when the form is submitted (and this property must be specified in the select tag). I checked the Struts docs and found out about the "Indexed" property of the html:select, I also found a doc at this URL: http://struts.apache.org/faqs/indexedprops.html that describes more or less what I need to do, but I tried to do it in the described way and it doesn't works, so I need help with this problem ASAP.
In the resulting html the selects are rendered like this:
(That's when the ArrayList contains two objects)
One thing that makes me curious is that the brackets are in the form, shouldn't it read crearServicioForm.codValorSeleccionado[i] ???
An interesting fact is that the page gets displayed without errors, thus I suppose that struts is finding a match between the codValorSeleccionado property in the page and the methods in the formbean. But it just doesn't works, no errors in the server console, but doesn't works.
I debugged and found out that in the action that gets called when submitting the page, the "getCodValorSeleccionado()" method of the formbean returns an empty array, thus the setCodValor... method that struts invokes is not filling the array.
In the document about indexed tags in the jakarta docs they talk about some way to handle "the wrinkle" of using indexed tags, in that you put the name of your member variable in the "name" atribute, but they show it with a html:text tag... I tried to do a similar thing with my select tag and the server reported an error of "codValorSeleccionado bean not found in any scope" which sound logical.
I also tried a method they described in which they use the IndexId of the iterate tag, and not the indexed of the html tag. Then they use a scriptlet to render that index in the property attribute. But that way doesnt work... it reports an arrayoutofbound error.
If you need any additional info or code let me know... but please give me some light on this.
At first glance it looks like you're using heml:select and html ptions the wrong way around, the options should point to your collection of beans the user is able to select from while the select tag point to a single String object in your form class that holds the value of the specific object selected by the user. It looks to me like your select tag points to an array