ui:repeat不适用于f:selectItem [英] ui:repeat doesn't work with 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.
推荐答案
<f:selectItem>
是标记处理程序(如JSTL).标记处理程序在视图构建期间运行,而UI组件则在视图呈现期间运行.因此,在<ui:repeat>
运行时,没有<f:selectItem>
的手段.
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屋!