wood burning stoves 2.0*
The moose likes Servlets and the fly likes question about drop down menus and servlets... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "question about drop down menus and servlets..." Watch "question about drop down menus and servlets..." New topic
Author

question about drop down menus and servlets...

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Hey guys. I have a form with several drop down menus. The form is validated and if there's something wrong the user has to fill it out again. How do I keep what the user has selected in the drop down and the other options as well?
thanks


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by Andres Gonzalez:
Hey guys.
I have a form with several drop down menus. The form is validated and if there's something wrong the user has to fill it out again. How do I keep what the user has selected in the drop down and the other options as well?
thanks

dear
every drop down must be having a unique name i.e something like <select name="dropdown">. u can retrieve the value user has selected by using request.getParameter("dropdown"). & similarly for other drop downs...
hth
malhar
ernest fakudze
Ranch Hand

Joined: Aug 27, 2001
Posts: 216
Try what Malhar has suggested Andres because that's how it's done. If you are still stuck then ask for code sample and I should be able to craft you an example. Things are a bit complex when you are populating the dropdown list from a database though...Good luck buddy!


In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
thanks guys... I think i got it my own way .
I have a bean, so I know what the user has selected. If there's an error in the form, I display all the values in the drop down menu, but the first option will be like this
<option checked><%=bean.getSelectetItem()%>
<option> another option </option>
.
.
or something like that, i don't have the code in this computer. So he/she can still choose a different option.
The disadvantage is that the option that the user has selected is shown twice. One at the very first option (what the use chose) and the same option where it originally was placed.
I was stuck with this problem for such a long time that didn't see any other solution.
Hope you guys understand what I explained above
.
thanks again
Debanjana Dasgupta
Ranch Hand

Joined: Aug 11, 2000
Posts: 101
Hi
You could keep al the options of the dropdpwn in a ArrayList .
Your bean will give you the selectedItem.
For populating the dropdown you could have a for loop and inside the loop get the items from the list arrayList.getItem(index) .
You could have a check to see if the
arrayList.getItem(index).toString().equals(bean.getSelected())
to keep the option selected.
Thanks
Debanjana


Thanks<br /> <br />Debanjana<br /> <br />SCJP2<br />SCEA
 
GeeCON Prague 2014
 
subject: question about drop down menus and servlets...