0

I need to create a selectOneMenu list for the day of birth. I need something like this:

for(int i=1;i<32;i++)
system.out.println(i);

How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Meryem Farouq
  • 11
  • 1
  • 1

3 Answers3

2

What you need is to use f:selectItems. There is also a good wiki page at StackOverflow.

And by the way, to select a date, you could use a date picker of a rich component library like PrimeFaces or RichFaces.

Community
  • 1
  • 1
LaurentG
  • 11,128
  • 9
  • 51
  • 66
  • 1
    Or if OP doesn't want to add a datepicker from one of those libraries, he/she could use a `` and decorate it with a jQuery component, but the datepicket component would be a better idea. – Luiggi Mendoza Aug 04 '13 at 17:40
0

One way of doing that is creating a list in the backing bean with the values and return them in view using selectIems. For example:

@ManagedBean
public class ManagedBean{
    private ArrayList list;


    @PostConstruct
    public void init(){
        for(int i=1; i<32;i++)
            list.add(i);
    }

    //getter and setter
}

in the view:

<h:selectOneMenu value="#{managedBean.someValue}">
     <f:selectItems value="#{managedBean.list}" var="day" itemValue="#{day}" itemLabel=#{day}/>
</h:selectOneMenu>
fareed
  • 3,034
  • 6
  • 37
  • 65
0

Without backing bean:

<h:selectOneMenu value="#{...}"  >              
    <c:forEach var="i" begin="1" end="31">
        <f:selectItem itemLabel="#{i}" itemValue="#{i}" />       
    </c:forEach>
</h:selectOneMenu>
joeker
  • 1
  • 1