选择primefaces datatable的compositeComponent不返回对象

选择primefaces datatable的compositeComponent不返回对象,primefaces,datatable,selection,composite-component,Primefaces,Datatable,Selection,Composite Component,我使用primefaces 5.1制作了一个复合组件。我想显示一个对话框,您可以输入一个名称并搜索数据库。然后,您可以选择一个条目,对话框将再次关闭。我的问题是dataTable中的选择总是返回null 这是合成图: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/htm

我使用primefaces 5.1制作了一个复合组件。我想显示一个对话框,您可以输入一个名称并搜索数据库。然后,您可以选择一个条目,对话框将再次关闭。我的问题是dataTable中的选择总是返回null

这是合成图:

    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:rich="http://richfaces.org/rich"
        xmlns:a4j="http://richfaces.org/a4j" xmlns:p="http://primefaces.org/ui"
        xmlns:composite="http://java.sun.com/jsf/composite">


    <composite:interface componentType="searchCustomer">
        <composite:attribute name="customerCache" required="true"
            type="com.hji.tis.ui.cache.customer.CustomerCache" />
        <composite:attribute name="useExtendedCustomersOnly" default="false" />
    </composite:interface>

    <composite:implementation>
        <p:commandLink styleClass="ui-icon ui-icon-search"
            id="searchCustomerIcon" onclick="PF('searchCustomerDialog').show();" />
        <p:tooltip for="searchCustomerIcon"
            value="#{msgs['request.searchByCustomerNumber']}" />

        <p:dialog header="#{msgs['general.searchCustomer']}" resizable="false"
            draggable="false" width="500" height="450" modal="true"
            appendTo="@(body)" widgetVar="searchCustomerDialog">
            <p:panel id="searchCustomerDialogContent" style="width:100%">
                <p:panelGrid style="width:480px">
                    <p:row>
                        <p:column style="width:60px">
                            <p:graphicImage value="/resources/images/userSearch.png"
                                width="50" height="50" />
                        </p:column>
                        <p:column style="width:100px">
                            <p:outputLabel value="#{msgs['general.customerName']}" />
                        </p:column>
                        <p:column style="width:160px">
                            <p:inputText value="#{cc.custSearch_name}"
                                id="input_searchCustomerName" />
                        </p:column>
                        <p:column>
                            <p:commandLink styleClass="ui-icon ui-icon-search"
                                action="#{cc.findCustomersByName}"
                                update="searchCustomerDialogContent"
                                process="@this, input_searchCustomerName" partialSubmit="true" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column colspan="4">
                            <p:dataTable value="#{cc.filteredCustomers}" var="customer"
                                scrollable="true" scrollHeight="300"
                                emptyMessage="#{msgs['general.noSelection']}"
                                selection="#{cc.selectedCustomer}" rowKey="#{customer.id}"
                                selectionMode="single">
                                <p:ajax event="rowSelect" process="@this" />
                                <p:column headerText="#{msgs['general.customerName']}"
                                    styleClass="unmarkable">
                                    <h:outputText value="#{customer.fullName}"
                                        rendered="#{!customer.extendedCustomer}" />
                                    <h:outputText value="#{customer.name}"
                                        rendered="#{customer.extendedCustomer}" />
                                </p:column>
                                <p:column headerText="#{msgs['general.address']}"
                                    styleClass="unmarkable">
                                    <h:outputText
                                        value="#{customer.homeAddress.address.country}, #{customer.homeAddress.address.zipCode} #{customer.homeAddress.address.city}, #{customer.homeAddress.address.street} #{customer.homeAddress.address.houseNr}" />
                                </p:column>
                            </p:dataTable>
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column colspan="4">
                            <p:commandButton icon="ui-icon-check" style="float:right"
                                action="#{cc.test}" process="@this, searchCustomerDialogContent"
                                partialSubmit="true" />
                        </p:column>
                    </p:row>
                </p:panelGrid>
            </p:panel>
        </p:dialog>
    </composite:implementation>
    </html>

这是Faces组件:

        package com.hji.tis.ui.util.customComponents;

    import java.io.IOException;
    import java.util.List;

    import javax.faces.component.FacesComponent;
    import javax.faces.component.UINamingContainer;
    import javax.faces.context.FacesContext;

    import lombok.Getter;
    import lombok.Setter;

    import org.primefaces.event.SelectEvent;

    import com.hji.tis.domain.model.customer.Customer;
    import com.hji.tis.ui.cache.customer.CustomerCache;

    /**
     * NamingContainer for the custom element searchCustomer.
     * 
     * @author mayra
     *
     */
    @FacesComponent("searchCustomer")
    public class SearchCustomer extends UINamingContainer {
        private final String CUSTOMER_CACHE = "customerCache";
        private final String USER_EXTENDED_CUSTOMERS_ONLY = "useExtendedCustomersOnly";
        private final String FILTERED_CUSTOMERS = "filteredCustomers";
        private final String SELECTED_CUSTOMER = "selectedCustomer";

        @Getter
        @Setter
        private String custSearch_name;

        @Getter
        @Setter
        private Customer custSearch_selectedCustomer;

        @Override
        public void encodeBegin(FacesContext facesContext) throws IOException {
            initCustomerCache();
            initUseExtendedCustomersOnly();

            super.encodeBegin(facesContext);
        }

        public void onRowSelect(SelectEvent event) {
            System.out.println(((Customer) (event.getObject())).getFullName());
        }

        /**
         * finds the customer by the name set to the _Name field. Decides wether
         * only private Customers should be returned or extended.
         */
        public void findCustomersByName() {
            this.custSearch_selectedCustomer = null;
            if (useExtendedCustomersOnly()) {
                setFilteredCustomers(getCustomerCache().findExtendedCustomerEntriesByName(custSearch_name));
            } else {
                setFilteredCustomers(getCustomerCache().findAllCustomerEntriesByName(custSearch_name));
            }
        }

        private boolean useExtendedCustomersOnly() {
            return getStateHelperValue(USER_EXTENDED_CUSTOMERS_ONLY);
        }

        private CustomerCache getCustomerCache() {
            return getStateHelperValue(CUSTOMER_CACHE);
        }

        public Customer getSelectedCustomer() {
            return (Customer) this.getStateHelper().get(SELECTED_CUSTOMER);
        }

        public void setSelectedCustomer(Customer customer) {
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!HERE THE CUSTOMER IS ALWAYS NULL
            this.getStateHelper().put(SELECTED_CUSTOMER, customer);
        }

        public List<Customer> getFilteredCustomers() {
            return (List<Customer>) this.getStateHelper().get(FILTERED_CUSTOMERS);
        }

        private void setFilteredCustomers(List<Customer> customers) {
            this.getStateHelper().put(FILTERED_CUSTOMERS, customers);
        }

        /**
         * stores the customerCache in the state helper.
         */
        private void initCustomerCache() {
            CustomerCache customerCache = getAttributeValue(CUSTOMER_CACHE);
            this.getStateHelper().put(CUSTOMER_CACHE, customerCache);
        }

        private void initUseExtendedCustomersOnly() {
            String value = getAttributeValue(USER_EXTENDED_CUSTOMERS_ONLY);
            boolean boolValue = false;
            if (value.equalsIgnoreCase("TRUE")) {
                boolValue = true;
            } else {
                boolValue = false;
            }

            this.getStateHelper().put(USER_EXTENDED_CUSTOMERS_ONLY, boolValue);
        }

        /**
         * Return specified attribute value or otherwise the specified default if
         * it's null.
         */
        @SuppressWarnings("unchecked")
        private <T> T getAttributeValue(String key) {
            return (T) this.getAttributes().get(key);
        }

        @SuppressWarnings("unchecked")
        private <T> T getStateHelperValue(String key) {
            return (T) this.getStateHelper().get(key);
        }

    }
package com.hji.tis.ui.util.customComponents;
导入java.io.IOException;
导入java.util.List;
导入javax.faces.component.FacesComponent;
导入javax.faces.component.UINamingContainer;
导入javax.faces.context.FacesContext;
进口龙目吸气剂;
进口龙目织机;
导入org.primefaces.event.SelectEvent;
导入com.hji.tis.domain.model.customer.customer;
导入com.hji.tis.ui.cache.customer.CustomerCache;
/**
*自定义元素searchCustomer的NamingContainer。
* 
*@作者玛拉
*
*/
@FacesComponent(“搜索客户”)
公共类SearchCustomer扩展了UINamingContainer{
私有最终字符串CUSTOMER\u CACHE=“customerCache”;
私有最终字符串USER\u EXTENDED\u CUSTOMERS\u ONLY=“useExtendedCustomersOnly”;
私有最终字符串筛选的\u CUSTOMERS=“filteredCustomers”;
选择的私有最终字符串\u CUSTOMER=“selectedCustomer”;
@吸气剂
@塞特
私有字符串custu名称;
@吸气剂
@塞特
私人客户搜索\您选择的客户;
@凌驾
public void encodeBegin(FacesContext FacesContext)引发IOException{
initCustomerCache();
inituseExtendedCustomerOnly();
super.encodeBegin(facesContext);
}
行上的公共无效选择(选择事件事件){
System.out.println(((客户)(event.getObject()).getFullName());
}
/**
*通过设置到_name字段的名称查找客户。决定是否
*只能退回或延长私人客户。
*/
public void findCustomersByName(){
this.custSearch\u selectedCustomer=null;
如果(useExtendedCustomersOnly()){
setFilteredCustomers(getCustomerCache().findExtendedCustomerEntriesByName(custSearch_name));
}否则{
setFilteredCustomers(getCustomerCache().findAllCustomerEntriesByName(custSearch_name));
}
}
专用布尔值useExtendedCustomersOnly(){
返回getStateHelperValue(仅限用户\扩展\客户\用户);
}
私有CustomerCache getCustomerCache(){
返回getStateHelperValue(客户缓存);
}
公共客户getSelectedCustomer(){
返回(客户)this.getStateHelper().get(所选客户);
}
公共无效设置选定客户(客户){
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!这里的客户总是空的
this.getStateHelper().put(所选客户,客户);
}
公共列表getFilteredCustomers(){
返回(列出)this.getStateHelper().get(过滤的客户);
}
私有void setFilteredCustomers(列出客户){
this.getStateHelper().put(过滤的客户,客户);
}
/**
*将customerCache存储在状态帮助器中。
*/
私有void initCustomerCache(){
CustomerCache CustomerCache=getAttributeValue(客户缓存);
this.getStateHelper().put(客户缓存,客户缓存);
}
private void initUseExtendedCustomersOnly(){
字符串值=getAttributeValue(仅限用户\u扩展\u客户\u);
布尔布尔布尔值=假;
if(value.equalsIgnoreCase(“TRUE”)){
布尔值=真;
}否则{
布尔值=假;
}
this.getStateHelper().put(仅限用户\扩展\客户\布尔值);
}
/**
*返回指定的属性值或指定的默认值,如果
*它是空的。
*/
@抑制警告(“未选中”)
私有T getAttributeValue(字符串键){
返回(T)this.getAttributes().get(key);
}
@抑制警告(“未选中”)
私有T getStateHelperValue(字符串键){
返回(T)this.getStateHelper().get(键);
}
}
也许有人知道原因

谢谢