1

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

Master Azazel
  • 491
  • 1
  • 10
  • 25
  • Did you created a jsf conversor for user class? Do you initialize `#{userAdministrationController.selectItemList}` with desired users to be shown as selected? – malaguna Dec 31 '15 at 14:39
  • i have tried using omnifaces generic converter but that didnt help at all the selectitemlist is the list with all users the selectedusers is the list with the users i want to have loaded as checked – Master Azazel Jan 01 '16 at 19:40

1 Answers1

3

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

Community
  • 1
  • 1
Master Azazel
  • 491
  • 1
  • 10
  • 25
  • And even have a good hascode and equals method: https://stackoverflow.com/questions/29944249/how-do-uiselectone-and-uiselectmany-components-preselect-defaults-in-fselectite/29945245#29945245 – Kukeltje Aug 09 '19 at 16:48