It's not a secret anymore!*
The moose likes Struts and the fly likes Struts indexed html:select , PLZ HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts indexed html:select , PLZ HELP" Watch "Struts indexed html:select , PLZ HELP" New topic
Author

Struts indexed html:select , PLZ HELP

Jorge Rodriguez
Greenhorn

Joined: Oct 23, 2004
Posts: 1
Hello fellas!

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.

The code I'm using in the JSP is as this:



In the formbean "crearServicioForm" I have this:



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.

Thanks.

Jorge
[ October 23, 2004: Message edited by: Jorge Rodriguez ]
John Smith
Ranch Hand

Joined: Sep 02, 2004
Posts: 61
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts indexed html:select , PLZ HELP
 
Similar Threads
Populating 'html:select' with values in Database
html:select indexed - idexes the formbean i.s.o. the property
Indexed Properties Help!!!
using c:out in a href and html:select
how to use list box in struts and how to retrive values in edit page