有没有办法动态创建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>
但它不起作用。
有什么想法吗?
答案 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}" />