0

I have 2 lists, one with elements for h:selectOneMenu (with have integer itemValue and string itemLabel) and one for h:dataTable(with have Id with should be display in selectOneMenu like default value. How to set default value for selectOneMenu by id taked from other list. Need to get something like that:

for(role.roleId == o.userRoleId){ //do something}

And real code is:

<h:dataTable value="#{accountsManagmentBean.users}" var="o"
            border="0" 
            styleClass="users-table"
            headerClass="users-table-header"
            rowClasses="users-table-odd-row,users-table-even-row">
            <h:column>
                <f:facet name="header">role</f:facet>

                <h:selectOneMenu value="#{accountsManagmentBean.roles}">
                    <f:selectItems value="#{accountsManagmentBean.roles}" var="role" itemValue="#{role.roleId}" itemLabel="#{role.roleName}" />
                    #{o.userRoleId} //default value Id
                </h:selectOneMenu>
            </h:column>

And bean class

@ManagedBean
@SessionScoped
public class AccountsManagmentBean implements Serializable{

private static final long serialVersionUID = 1L;

private DataModel<UserModel> users;

private List<RoleModel> roles;

@PostConstruct
public void init() {
    GetUsersService getUsersService = new GetUsersService();
    List<UserModel> usersList = getUsersService.getUsers();
    UserModel[] usersArray = usersList.toArray(new UserModel[usersList.size()]);
    users = new ArrayDataModel<UserModel>(usersArray);

    RoleService roleService = new RoleService();
    roles = roleService.getRoles();
}

public DataModel<UserModel> getUsers() {
    return users;
}

public List<RoleModel> getRoles() {
    return roles;
}
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Faron
  • 123
  • 14
  • 1
    Why don't you just do `` as shown in every JSF tutorial? – BalusC Oct 12 '15 at 08:51
  • Case is that: user need to change "user role". For that i want to use selectOneMenu. The default value user should know what role is now. By changing role in selectOneMenu he change "user role" in database. O.userRoleId is only id and i want to display role name. Role names i took from other class. – Faron Oct 12 '15 at 08:58
  • Your suggestion is the answer for my question. It was so simply. I am ashamed for this question :P – Faron Oct 12 '15 at 09:04

0 Answers0