Master Azazel
Master Azazel

Reputation: 600

Primefaces selectManyMenu-> loading default values

im using jsf 2.2 majorra and primefaces 5.1 to build a webapp

i know this has probably been answered before, but i dont find my error... i took examples from the primefaces showcase and tried some stuff suggested by the internet, but it doesnt want to work

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/WEB-INF/template/master.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:pe="http://primefaces.org/ui/extensions"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

    <ui:define name="content">

        <p:selectManyMenu id="userList"
            value="#{userAdministrationController.selectedUsers}" var="t"
            filter="true" filterMatchMode="contains" showCheckbox="true">
            <f:selectItems value="#{userAdministrationController.selectItemList}"
                var="user" itemLabel="#{user.fullName}" itemValue="#{user}" />
            <p:column>
                <h:outputText value="#{t}" />
            </p:column>
        </p:selectManyMenu>
        <p:separator />
        <p:commandButton value="Submit" oncomplete="PF('dlg').show()"
            icon="ui-icon-check" />
    </ui:define>
</ui:composition>

im trying to load this list so that some users are already selected when visiting the page, like a default value

all users show as desired, but no default values are loaded to the checkboxes

thanks in advance

Upvotes: 1

Views: 4225

Answers (1)

Master Azazel
Master Azazel

Reputation: 600

okay now i found the answer:

working code->

    <p:selectManyMenu id="userList"
        value="#{userAdministrationController.selectedUsers}" var="t" 
        filter="true" filterMatchMode="contains" showCheckbox="true" >
        <f:selectItems value="#{userAdministrationController.selectItemList}"
            var="user" itemValue="#{user}" />
        <p:column>
            <h:outputText value="#{t}"  />
        </p:column>
    </p:selectManyMenu>

without the converter! and in my bean i had to make a List for the preselected values, the stuff in the list has to be the same type as the VALUES of the selectitems

    List<User> inactiveUsers = userService.findByActive(false);
    List<User> userList = userService.findAll();

    selectItemList = new ArrayList<SelectItem>();
    for (User user : userList) {
        SelectItem selectItem = new SelectItem(user.getFullName(), WordUtils.capitalize(user.getFullName()));
        selectItemList.add(selectItem);
    }

    selectedUsers = new ArrayList<String>();
    for (User user : inactiveUsers) {
        String userName = user.getFullName();
        selectedUsers.add(userName);
    }

screenshot of control

Upvotes: 3

Related Questions