Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ebert Roger
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Davie Lin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!