The moose likes Struts and the fly likes Problem submitting html:select value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem submitting html:select value" Watch "Problem submitting html:select value" New topic

Problem submitting html:select value

Satyajeet Kumar

Joined: Jun 06, 2006
Posts: 1
Hello Ranchers,

I have a <html:select> pull down list in my jsp page that is populated with values from database. I have used Arraylist in my Form-bean to populate the pull down list.

Now, when i am submitting the page i want the value selected in the pull down list (for some comparison purposes) in my Action class.

So, how will i get the selected value?
The problem is the Getter method in my Form-bean returns ArrayList and not String (as I have used ArrayList to populate the html:select control).

My Form bean :

My Jsp Page :

Pls, help out?
Pallavi ch
Ranch Hand

Joined: Dec 16, 2004
Posts: 76
Try this...

<html:select property="cityName">
<html ptionsCollection name="InfoForm" property="city" label="cLbl" value="cValue" />

and in the form bean - define this "cityName" variable and write getter and setter for that.
In your Action class, u get the selected value by using getCityName().
Siddharth kumar

Joined: Jun 07, 2006
Posts: 6
So, Lavanya do u mean in the same form bean a variable named cityName should be used.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
You are correct. Generally your form will have one property that represents the value of the selected item (this property is typically a String or long/int) and another property that represents all the available values in the list (this property can be some type of Collection or an array, I think).

- Brent
Siddharth kumar

Joined: Jun 07, 2006
Posts: 6
Thanks, got it
I agree. Here's the link:
subject: Problem submitting html:select value
It's not a secret anymore!