如何动态创建< f:selectItem>列表? [英] How to dynamically create a <f:selectItem> list?

查看:101
本文介绍了如何动态创建< f:selectItem>列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种动态创建selectItem列表的方法?我真的不想创建大量的Bean代码来使我的列表返回List<SelectItem>.

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>.

我尝试过:

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

但它不起作用.

有什么想法吗?

推荐答案

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

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}" />

另请参见:

  • 我们的<h:selectOneMenu> Wiki页面
  • See also:

    • Our <h:selectOneMenu> wiki page
    • 这篇关于如何动态创建&lt; f:selectItem&gt;列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆