ui:repeat不适用于f:selectItem [英] ui:repeat doesn't work with f:selectItem

查看:116
本文介绍了ui:repeat不适用于f:selectItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用菜单上的icefaces select从用户列表中选择一个用户 我想为每个用户重复执行selectItem 这是我尝试过的:

i am using icefaces select on menu to select a user from list of users and i want to repeat the selectItem for each user here's what i tried:

<ice:selectOneMenu id="users">
    <ui:repeat value="#{user.getUserList()}" var="user">
        <f:selectItem itemLabel="#{user.name}" itemValue="#{user.id}"/>
    </ui:repeat>               
</ice:selectOneMenu> 

UserBean:

@Component("user")
@Scope("view")
Public class UserBean{

Public List<User> getUserList() throws Exception {
        return userService.getAllUsers();
    }

}

注意::UserBean不包含属性id,即它们存在于User实体中的名称. 请指教,谢谢.

NOTE: UserBean doesn't contains the properties id,name they exist in User entity. please advise, thanks.

推荐答案

The <ui:repeat> is an UI component while <f:selectItem> is a taghandler (like JSTL). Taghandlers runs during view build time before UI components which runs during view render time. So at the moment the <ui:repeat> runs, there is no means of a <f:selectItem>.

一个也是标签处理程序的<c:forEach>可以工作,但更好的方法是使用

A <c:forEach>, which is also a tag handler, would work, but much better is to use <f:selectItems> instead. Since JSF 2.0 it can take a collection and support the var attribute as well:

<ice:selectOneMenu id="users">
    <f:selectItems value="#{user.usersList}" var="userItem" 
        itemLabel="#{userItem.name}" itemValue="#{userItem.id}" />
</ice:selectOneMenu>

请注意,var属性不应与作用域中的现有bean冲突.

Note that the var attribute should not clash with an existing bean in the scope.

这篇关于ui:repeat不适用于f:selectItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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