• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 67746
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: 67746
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: 67746
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.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic