0

I am VERY new to JSF, and I need some help doing, what I thought would be, a very simple task. I would like to populate a selectonemenu from an array or loop or something. I have a form where I want the user to enter their DOB. All I want is a simple list where they can select from 1..31 for the day of month. I don't want to have 31

<f:selectItem value="n" />

tags. I attempted to put a "getDates" method in my backing bean, but that didn't work well. Any advice on how to do this will be greatly appreciated.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Brian
  • 1,726
  • 2
  • 24
  • 62
  • Psssh.. Put your mouse above the `[selectonemenu]` tag which you've placed on the question yourself until a black info box pops up and then click therein the *info* link. – BalusC Jun 13 '12 at 21:26

1 Answers1

5

You need <f:selectItems> instead of <f:selectItem>. The <f:selectItems> can take a List<T> or T[] or even a Map<K,V>.

E.g.

<h:selectOneMenu value="#{bean.selectedItem}">
    <f:selectItems value="#{bean.availableItems}" />
</h:selectOneMenu>

with

private String selectedItem;
private List<String> availableItems;

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555