Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Drop Down List

 
Michael James Payne
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I mainitain the selected value from the dropdown list so when the jsp is redisplayed, the selected values are maintained (are shown) and not lost?



Michael J. Payne
Consultant
Fusion Alliance
Indianapolis, Indiana
 
Stefan Evans
Bartender
Posts: 1751
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to generate appropriate HTML to indicate which records in the list are selected.
Basically for whichever option is selected, you have to have <option value="42" selected="true">

Frameworks like struts/JSF will often take care of this for you, otherwise you do it manually, with an if statement in the middle of your rendering the list.
Another approach is to render the list as usual, and then execute a javascript command onload which sets the value. It sometimes looks a bit neater in code ;-)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One caveat:

selected="true"

is probably a poor way to express this because it would lead one to believe that saying selected="false" would have the opposite effect.

In XHTML, if anything is supplied as a value to the selected attribute -- be it selected="true" or selected="false" or even selected="sdhsjhdsh" -- the option will be selected.

This is true of all attributes that have no value in HTML but must have a value in XHTML.

The standard means of expressing these is to repeat the name of the attribute. E.g. selected="selected".
[ October 19, 2006: Message edited by: Bear Bibeault ]
 
toukhir mujawar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...

just try this one...

<option value="1" selected>

this is sufficient... need not write select= "true"/false/anything else...
 
reddy yeruva
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok if you want the selected value in the page after refresh means again you are sending it to the same page yes..

simple

place in javascript as

lacation="pagename.jsp?&yourattribute=value"

simple
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by toukhir mujawar:
need not write select= "true"/false/anything else...


Depends upon whether you are using HTML or XHTML. In the latter, the value is required.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic