my dog learned polymorphism*
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
Author

Problem submitting html:select value

Satyajeet Kumar
Greenhorn

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?
Lavanya ch
Ranch Hand

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

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

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
Greenhorn

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
Greenhorn

Joined: Jun 07, 2006
Posts: 6
Thanks, got it
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem submitting html:select value
 
Similar Threads
dynamic value to be submitted to form beans
html:optionsCollection from a DynaActionForm
Form Params not passed properly
Struts indexed html:select , PLZ HELP
DynaValidator reset options being reset.