Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about drop down menus and servlets...

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic