Avatar of buckrodger
buckrodger

asked on 

JSF selectonemenu default selection

I have a selectOnemenu in my jsp.  I have it populating just fine with an array of SelectItem, but how can I set the item selected by default ??
<h:selectOneMenu styleClass="textFields"
                             value="#{userProfile.periodEnding}"  >
              <f:selectItems value="#{infoverificationController.selectItems}" />             
            </h:selectOneMenu>

Open in new window

Java EEJavaWeb Applications

Avatar of undefined
Last Comment
buckrodger
ASKER CERTIFIED SOLUTION
Avatar of brunoguimaraes
brunoguimaraes
Flag of Brazil image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of buckrodger
buckrodger

ASKER

This worked, but I needed to remove the <f:selectItems> otherwise it added twice.
// backing bean code
	
public HtmlSelectOneMenu getPeriodEndings(){
  HtmlSelectOneMenu menu = new HtmlSelectOneMenu();
  UISelectItems items = new UISelectItems();
  items.setValue(selectItems);
  menu.getChildren().add(items);
  // i set "selected" in the method that populates my arraylist.
  menu.setValue(selected);
  return menu;
}
 
// jsp code 
<h:selectOneMenu styleClass="textFields"
      binding="#{infoverificationController.periodEndings}"
      value="#{userProfile.periodEnding}"  >
</h:selectOneMenu>

Open in new window

Avatar of buckrodger
buckrodger

ASKER

Thank you, this worked
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo