What is the best way to redisplay a previously selected value in a drop down? For example I have a drop down and the user selects a value. I store that value in a bean. When the user returns to the page I want that value to be the selected one in the drop down. Right now I am doing this which is working, but I don't think it is the right way because I can't default to anything now. I am going to have to do the same thing on a multi select also.
For the multi selects I saw a lot of examples. Is it just not an easy way like in struts to do this? I know what the option values are so I think it is cluncky to have to create an array of the values, then loop over them seeing if one is in my array of selected and then setting it as selected if it is?
How are you getting the values to the page if not in some sort of collection?
And, if you want a handy-dandy easy way to do it, define a custom action that will take care of all the gnarly details for you.
Joined: Sep 24, 2005
Yes the selected ones are put in an array list and then put on the request, but all the other ones are just static and were in the html. From the examples I saw you need two loops one to go through all the possible and one to see if it was selected. I guess some JSTL will make it a little better. When you say custom action, do you mean some kind of custom tag?
As of JSP 2.0 what used to be called the standard and custom "tags" are now known as "actions".