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?
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?
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.
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>
Without backing bean:
<h:selectOneMenu value="#{...}" >
<c:forEach var="i" begin="1" end="31">
<f:selectItem itemLabel="#{i}" itemValue="#{i}" />
</c:forEach>
</h:selectOneMenu>