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.
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.
selectOneMenu
wiki pagewhy 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With