Primefaces selectManyMenu->加载默认值 [英] Primefaces selectManyMenu-> loading default values

查看:62
本文介绍了Primefaces selectManyMenu->加载默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im使用jsf 2.2 majorra和primefaces 5.1构建Webapp

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

我知道以前可能已经回答了这个问题,但是我找不到我的错误...我从primefaces展示柜中拿了一些例子,尝试了互联网上提出的一些建议,但是它不起作用

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

预先感谢

推荐答案

好的,现在我找到了答案:

okay now i found the answer:

工作代码->

    <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>

没有转换器!在我的bean中,我必须为预先选择的值创建一个列表,列表中的内容必须与selectitems的VALUES类型相同

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);
    }

这篇关于Primefaces selectManyMenu-&gt;加载默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆