ui:repeat doesn't work with f:selectItem

戏子无情 提交于 2019-12-01 03:49:57

问题


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();
    }

}

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


回答1:


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

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>

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

See also:

  • selectOneMenu wiki page



回答2:


why not use f:selectItems. I think something like this would work.

<f:selectItems value="#{user.getUsersList()}" var="user" itemLabel="#{user.name}"
                                            itemValue="#{user.id}" />

EDIT also try removing the brackets from the user.getUsersList() in your code , i think its not how you call a function in jsf2



来源:https://stackoverflow.com/questions/8152322/uirepeat-doesnt-work-with-fselectitem

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