943,708 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 7366
  • JSP RSS
Sep 19th, 2008
0

Pre selecting combo box in JSP

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
comsec is offline Offline
3 posts
since Sep 2008
Sep 19th, 2008
0

Re: Pre selecting combo box in JSP

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:-
html Syntax (Toggle Plain Text)
  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>
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Sep 20th, 2008
0

Re: Pre selecting combo box in JSP

<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)
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is online now Online
6,656 posts
since Dec 2004
Sep 22nd, 2008
0

Re: Pre selecting combo box in JSP

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
comsec is offline Offline
3 posts
since Sep 2008
Sep 22nd, 2008
-1

Re: Pre selecting combo box in JSP

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...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is online now Online
6,656 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Connection Pooling in Java
Next Thread in JSP Forum Timeline: Re: Java program need help!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC