aspose file tools*
The moose likes JSP and the fly likes JSP and Dropdown Box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP and Dropdown Box" Watch "JSP and Dropdown Box" New topic
Author

JSP and Dropdown Box

Mike Vat
Greenhorn

Joined: Sep 09, 2008
Posts: 10
HI friends,

I need your help. I am new to jsp. here is my questions.

I ahev a JSP page with a dropdown box. When the page first loads it gets data from teh server and loads the dropdown box. The user selects one value and hit submit. First I am self submitting the page to do the server side validations. But the problem is when it reloads the dropdown box is refilled and it is not retaining the data that the user selected before the submit.

For eg: teh DROP DOWN has the follwoing entries.

Value 1
Value 2
Value 3
.. Teh user selected Value 3 in the dropdown and submitted the Page.
When it reloads after the validation, it is loosing its previous value (Selection of Value 3) and the dropdown is again defaults to "Value 1"

Can any body please help me how I should be able to retain the previous value which is "value 3" even after I reloads the page ?

Thanks very much for your help.

mike
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Please use real words when posting to the forums. Abbreviations such as "teh" in place of "the" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

On the round trip, use the submitted value to set the selected attribute on the option that you want to be selected.
Mike Vat
Greenhorn

Joined: Sep 09, 2008
Posts: 10
Thanks for the reply. This works. I will take care in my next post. thanks
Christian
Greenhorn

Joined: Dec 18, 2008
Posts: 1
Hi all,

I have a similar problem:

Put a DropDownList on the form and a Button, in the init method fill the dropdown list with some values:

ArrayList alList = new ArrayList();

if(isPostBack() == false) {
alList.add(new Option(1, "test 1"));
alList.add(new Option(2, "test 2"));

this.dropDown1.setItems(alList);
}

Select a value in the Dropdown and press the button, you get the selected value correctly in the eventhandler but the dropdown looses the selected value after the postback.

I am using Netbeans 6.5 and a Glassfish v2 (build using J2EE).

Does somebody can help or have a hint for me ?
(Normally I come from the ASP.NET World / C++ World so please forgive
me my small java knowledge...)


Kind regards


Christian
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Same answer. Use the submitted value to set the selected attribute of the option you want to be selected.
 
 
subject: JSP and Dropdown Box