Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JSP and Dropdown Box

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. This works. I will take care in my next post. thanks
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same answer. Use the submitted value to set the selected attribute of the option you want to be selected.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic