如何动态创建<f:selectitem>列表?</f:selectitem>

时间:2010-03-12 18:30:20

标签: jsf icefaces

有没有办法动态创建selectItem列表?我真的不想创建大量的bean代码来使我的列表返回List<SelectItem>

我试过了:

<ice:selectManyCheckbox>
    <ui:repeat var="product" value="#{productListingService.list}">
      <f:selectItem itemLabel="#{product.description}" value="#{product.id}"/>
    </ui:repeat>
</ice:selectManyCheckbox>

但它不起作用。

有什么想法吗?

1 个答案:

答案 0 :(得分:29)

请改用<f:selectItems>。它接受List<SelectItem>SelectItem[]旁边的Map<String, Object>作为值,其中地图关键字是项标签,地图值是项值。或者,如果您已经使用JSF 2.0,则可以使用List<SomeBean>代替var属性引用当前项目。

<f:selectItems value="#{productListingService.list}" var="product" 
    itemLabel="#{product.description}" itemValue="#{product.id}" />

另见: