compositeComponent with primefaces datatable selection does not return object -
i've made composite component using primefaces 5.1. want dialog show up, can input name , search db. can select 1 entry , dialog closes again. problem ist selection in datatable returns null...
this composite:
<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>
and faces component:
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 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 customer name set _name field. decides wether * private customers should 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 customer 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 customercache in 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 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); } }
maybe knows reason why?
thanks!
Comments
Post a Comment