0
votes

I've read some tutorials where it was mentioned, that the only way you can set a default drop-down menu option is by ordering the options(SelectItems) list. But i am unable to do so.

The following is my XHTML:

<p:selectOneMenu ....>
    <p:ajax event="change" update="ordersListForm" />
    <f:selectItems value="#{Controller.memberList}"
        var="User" itemLabel="#{User.authority.fullName}"
        itemValue="#{User.authority.fullName}" />
</p:selectOneMenu>

and my Bean :

 currentUser = loginManager.getCurrentPrincipal().getUser();
 memberList = new ArrayList<>();
 List<SiteMember> tempList = memberManager.getList();
 currentUserNN = isUserNN(currentUser);
 for (SiteMember member : tempList) {
    for (Group group : memberManager.getGroups(member.getAuthority().getUserName())) {
         if (group.getItemName().startsWith(Roles.ROLE)) {
            memberList.add(member);
         }
    }
 }

So the default value depends which user has logged in and from which group he belongs to.

If user belongs to group ROLE then his name should be the default option. If he doesn't belong to that group, the selectItems should be memberList ordered alphabetically.

If i can at least be shown how to make defaultUser as the default option, i can manage the rest.

Thanks in advance.

1
why cant you set the value attirubute of selectOneMenu as currentUser or null based on his user group and do a Collections.sort on the memberList? - Mahendran Ayyarsamy Kandiar
sort won't work on memberList. - DevyDev
can you be more specific? why sort wont work? - Mahendran Ayyarsamy Kandiar
It just sais that sort is not applicable for memberList. - DevyDev
please read mkyong.com/java/… whenever you get a chance. Thanks and good luck. - Mahendran Ayyarsamy Kandiar

1 Answers

0
votes

set the value of selectOneMenu to the current user group. If .startsWith(Roles.ROLE) true then set the value, else set the value to null.