wood burning stoves 2.0*
The moose likes JSP and the fly likes Retain option selected value on submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Retain option selected value on submit" Watch "Retain option selected value on submit" New topic
Author

Retain option selected value on submit

Sam Raoh
Greenhorn

Joined: Dec 21, 2009
Posts: 5
Hi all,

I have the following code


used for drop down list in my jsp, where utList is an Arraylist of Hashmaps from the backend database table. I am able to display the dropdown box but on submit I am not able to retain the selected value.

I do have a session.getAttribute set for the selected value in my servlet.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

How would you go about setting a particular selected option in the HTML? Once you figure that out, you change the JSP to make that happen.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sam Raoh
Greenhorn

Joined: Dec 21, 2009
Posts: 5
thanks...yeah I know that we have to use <option value="xyz" selected>...but I was wondering how we go about doing the same in that code?

I do have my program working when I use a String to display options, but I'd like to know if there is anyway we can do the same, using EL, when and arraylist of Hashmaps is used, as in the code displayed above?

Thank you
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hint : You can achieve it using EL and ternary operator.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

You know what the value of each option is, and you know what the selected value is, just compare them and when they are the same, add the selected attribute.

And no, I won't write the code for you. Give it a try and see what you come up with and we'll take it from there.
Sam Raoh
Greenhorn

Joined: Dec 21, 2009
Posts: 5
I got it working folks!
Thank you Vikas
Thanks, but No Thanks, but Thanks very much... Bear
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

It'd be cool if you could post your solution so that others with the same issue can benefit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retain option selected value on submit