Pre selecting combo box in JSP

Reply

Join Date: Sep 2008
Posts: 3
Reputation: comsec is an unknown quantity at this point 
Solved Threads: 0
comsec comsec is offline Offline
Newbie Poster

Pre selecting combo box in JSP

 
0
  #1
Sep 19th, 2008
I have a collections to be populated in a JSP combo box. Now suppose there is a different page for each user which displays user specific values in a combo box in that page.

The combobox should display the value from the collection specific to the user. But my combo box just shows the first value which is <html:option> value.

Anyone knows how to do that? I mean pre selecting (a selected value of combo box) a user specific value in combo box.

to make it more simpler, lets say there is a combo box called "Manager" in the user page and it should display different Manager for different users. And this combo box is having a collection of managers.
Last edited by comsec; Sep 19th, 2008 at 5:16 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1,175
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 125
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Pre selecting combo box in JSP

 
0
  #2
Sep 19th, 2008
This is more of an HTML question rather than a JSP question,

You have to add the parameter selected="selected" for the Option element you want to be selected by default.

An example is as follows:-
Consider you combobox has four elements Volvo, Saab, Fiat and Audi and you want Fiat selected by default, then you would have to do the following:-
  1. <html>
  2. <body>
  3. <form action="">
  4. <select name="cars">
  5. <option value="volvo">Volvo</option>
  6. <option value="saab">Saab</option>
  7. <option value="fiat" selected="selected">Fiat</option>
  8. <option value="audi">Audi</option>
  9. </select>
  10. </form>
  11. </body>
  12. </html>
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Pre selecting combo box in JSP

 
0
  #3
Sep 20th, 2008
<html:option> is used with Apache Struts something like this example (There is no explanation to code, just reference from which book the code come )
For stuts tutorial on form you may consider look at this tutorial, maybe this from from IBM (based on Websphere, but general logic can be re-used) or Advanced Forms Handling in Struts 1.1 (includes example of code in zip form)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: comsec is an unknown quantity at this point 
Solved Threads: 0
comsec comsec is offline Offline
Newbie Poster

Re: Pre selecting combo box in JSP

 
0
  #4
Sep 22nd, 2008
Thanks guys for your reply. I am using Struts tags here. I followed the tutorial there too. I have property set in the form and it has the value but it does not show up in the combo box as selected value. Combo box still shows the "-1" <html:option> value.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Pre selecting combo box in JSP

 
-1
  #5
Sep 22nd, 2008
I have no idea about the structure of your database what sort of data you keep but surly somewhere along you looking up/checking to what group user belong so you would be able to get this info and incorporate it in your selection...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JSP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC