File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes struts: html:options tag not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts: html:options tag not working" Watch "struts: html:options tag not working" New topic

struts: html:options tag not working

Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I have the following sort of working -

selectedGoalID is the get/set in my browseform (aka the browse bean)
I have a class called goal with a getName method.
The form returns an arraylist of goals.
The above tag will generate a select box with 4 options, the number of goals I have. The names are completely wrong, as I would expect. What I need is this -
- a value for each goal, the goal's id
- a displayed option, the goal's name
- the selected goal needs to remain selected after going through the action form
The following is what 'works' in the sense, it displays the names and has the value associated with id. It keeps reseting to the first option after going through the action though.

The Mastering Jakarata Struts book by J. Goodwill only provides a simple example. I haven't gotten a better understanding from the struts docs either.
What am I missing?
Aaron R>
[ September 26, 2002: Message edited by: Aaron Roberts ]
Ravi Veera
Ranch Hand

Joined: Jun 23, 2001
Posts: 127
Here's an example adaptedfrom my code which may be wwhat you are looking for

In this example in my pipingForm class I have an ArrayList element called projectUnits and a corresponding getProjectUnits method. The projectUnits ArrayList is populated with instances of the LabelValueBean class(having label and value properties).
[ September 27, 2002: Message edited by: Ravi Veeraghanta ]
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
I adjusted your example for my specific beans and methods and everything worked perfectly! Thank you so much for the help!
I was able to replace the half html / half struts select box I had created with a straight struts implementation.
If I understand it, the reason I couldn't just use the returned arraylist directly, was because the options tag only does a get on the property and labelproperty parameters. I had to already have a collection in the form bean or define it explicitly as you showed.
Best regards,
I agree. Here's the link:
subject: struts: html:options tag not working
It's not a secret anymore!