• 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

populate combox with list with default selected value

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an editable table. The table is populated with values when the page opens. I have a couple comboboxes that I populate. My problem isn't with populating the combobox. My problem is the value that Im getting from the database(I am positive I am getting the right value...) is not selected value when the page opens. Below is the code I am using to populate the combo box... How do I populate it and use the value I am getting from my bean to be the selected value when I open the page? Thanks.



The value I want to use is located at: ${lmgmt.uoi}

Thanks again!
 
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
First a terminology correction: it''s not a combobox (or even a combox). A ComboBox is a desktop control not available in HTML. Call it a select or a dropdown.

So how would you code the <select> and its options to select on of the options if you were wirting it in straight HTML?
 
Daniel Conner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be something like this:



I had tried doing something like that before, but with using expression language of course for the list and the variable. It printed the value from my bean twice. The first time it printed the value is the selected value and the second time it printed it from the list. It looked something like this:



Would it make sense to use <c:if to make sure that only the values from the list that are included in the list are the ones that aren't selected?
 
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
If you are using JSP 2.0 you can use the ternary operator (?) of the EL to conditionally evaluate an expression. This makes it easy to conditionally include or exclude the "selected" attribute from the <option> based upon whether the values match or not.

You can also do it with <c:if> but it's much wordier.
 
Daniel Conner
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome! Got it. Thanks Bear. You have been a lot of help... Not just on this topic, but also on other questions I have asked lately... Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic