This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Strange problem using html:select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Strange problem using html:select" Watch "Strange problem using html:select" New topic

Strange problem using html:select

Mohit Agarwal
Ranch Hand

Joined: Mar 30, 2004
Posts: 88

I am facing a strange problem using html:select .
The select property refers to state drop-down . The state is an attribute of the Address bean and the address bean is in turn a part of the form bean.

So based on my requirements i have instances of addresses in my form-bean as
previousAddress,currentAddress etc.

The problem is that the selected state is not appearing as selected when i return to this page.

I am using html:select property="previousAddress.state". But when i use bean:write property="previousAddress.state" i am getting the name of my selected state.

Is this a bug in struts or am i missing something . The selection is captured and while rendering of the page the choice is not appearing as selected.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Check to make sure the list of options actually contains an entry for which the value attribute is the same as the value of previousAddress.state. Do the values of your options contain state names or state abbreviations? Does previousAddress.state contain a name or abbreviation?

Consultant, Sima Solutions
Mohit Agarwal
Ranch Hand

Joined: Mar 30, 2004
Posts: 88

Thanks for your reply , its captured correctly and is there in the list of options as well , i am using LabelValueBean for the options , i had spent quiet some time on this , but nothing really came to know.

I put print statements in getters and setters of state attribute , on the console i can see that my option is getting captured, yet its not appaaring as selected .

Any help will be most appreciated.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I don't have any other ideas based on what you've said. If you'd like us to look at it further, post the relevant portions of:

3-Action Class
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
LabelValueBean you say. I guess I did not know that class existed back when I created a similar class for my project.

When you view the source of your page, what value do you see for the options? Like this example, what is there instead of XXX?

<option value="XXX">Virginia</option>

It is this value that you need to store in your action form. Here is a quick example I pulled from a JSP page. My form has property supervisorId that matches up with one of the "id" values, but it is the person's name that the user sees in the list.

- Brent
[ February 10, 2006: Message edited by: Brent Sterling ]
I agree. Here's the link:
subject: Strange problem using html:select
Similar Threads
html:select html:options error, no getter. please help
retaining selected values.....list box
submit the form in JSP
Problem submitting html:select value
how to get both value and text of selected item in action class