• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Dynamic HtmlSelectOneMenu : How to set the selected value in dropdown?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm dynamically building a HtmlSelectOneMenu as shown below. I need to build this component dynamically based on some Meta data and then set "6 mos" as the selected value on the dropdown list. How do i achieve this?

HtmlSelectOneMenu menu = new HtmlSelectOneMenu(); // combo box

menu.setId("menu_id");

// populate the drop down list
UISelectItems items = new UISelectItems();

List comboList = new ArrayList();

comboList.add(new SelectItem(" "));
comboList.add(new SelectItem("3 mos"));
comboList.add(new SelectItem("6 mos"));
comboList.add(new SelectItem("9 mos"));

items.setValue(comboList);
menu.getChildren().add(items); // add list to combobox
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ebert

I guess you will have to work out the dynamic list building part yourself, as far as set the "6 mos" as selected value
you will need to include value attribute in the <h:selectOneMenu> tag. The value attribute will point at the <managed-bean>'s prperty, so either you assign this property to "6 mos" or you assign this property based upon the dynamic list you generated for the drop-down if "6 mos" was not to be the selected value.

BTW, please use code tags like below

tags in the future when you post any code
Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic