How to dynamically create a <f:selectItem> list?

一曲冷凌霜 提交于 2019-11-27 21:14:00

问题


Is there a way to dynamically create a selectItem list? I dont really want to have to create lots of bean code to make my lists return List<SelectItem>.

I tried this:

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

but it doesnt work.

Any ideas?


回答1:


Use <f:selectItems> instead. It accepts next to List<SelectItem> and SelectItem[] also a Map<String, Object> as value where the map key is the item label and map value is the item value. Or if you're already on JSF 2.0, then you can use a List<SomeBean> instead where the current item can be referenced by the var attribute.

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

See also:

  • Our <h:selectOneMenu> wiki page


来源:https://stackoverflow.com/questions/2434902/how-to-dynamically-create-a-fselectitem-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!