• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange problem using html:select

 
Mohit Agarwal
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mohit Agarwal
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

1-ActionForm
2-JSP
3-Action Class
4-struts-config.xml
 
Brent Sterling
Ranch Hand
Posts: 948
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic