Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ui:repeat doesn't work with f: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();
    }

}

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

like image 587
Mahmoud Saleh Avatar asked Nov 16 '11 13:11

Mahmoud Saleh


2 Answers

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
like image 181
BalusC Avatar answered Oct 01 '22 13:10

BalusC


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

like image 42
Khizar Avatar answered Oct 01 '22 13:10

Khizar