简体   繁体   English

如何从循环或数组填充JSF selectonemenu

[英]How Can I Populate JSF selectonemenu From Loop or Array

I am VERY new to JSF, and I need some help doing, what I thought would be, a very simple task. 我是JSF的新手,我需要做一些非常简单的任务,我想这应该是。 I would like to populate a selectonemenu from an array or loop or something. 我想从数组或循环之类的东西中填充一个selectonemenu。 I have a form where I want the user to enter their DOB. 我有一个表格,希望用户输入其DOB。 All I want is a simple list where they can select from 1..31 for the day of month. 我想要的只是一个简单的列表,他们可以在每月的1..31中进行选择。 I don't want to have 31 我不想有31岁

<f:selectItem value="n" />

tags. 标签。 I attempted to put a "getDates" method in my backing bean, but that didn't work well. 我试图在后备bean中放入“ getDates”方法,但是效果不佳。 Any advice on how to do this will be greatly appreciated. 任何有关如何执行此操作的建议将不胜感激。

You need <f:selectItems> instead of <f:selectItem> . 您需要<f:selectItems>而不是<f:selectItem> The <f:selectItems> can take a List<T> or T[] or even a Map<K,V> . <f:selectItems>可以使用List<T>T[]甚至Map<K,V>

Eg 例如

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

with

private String selectedItem;
private List<String> availableItems;

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM