java - Problem with PrimeFaces and Composite Components -
i have piece of code similar "data table - instant row selection". however, when break down composite components selection values not displayed. have suspicion it's caused primefaces code.
below code doesn't work:
viewapplicationconfig.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:dti="http://java.sun.com/jsf/composite/dti" template="../../templates/basetemplate.xhtml"> <f:metadata> <f:viewparam name="contextapplicationid" value="#{viewapplicationconfig.contextapplicationid}"/> </f:metadata> <ui:define name="title">#{viewapplicationconfig.pagetitle}</ui:define> <ui:define name="content"> <p:panel id="panel" header="#{viewapplicationconfig.pagetitle}" style="width: 1280px"> <ui:remove> ------ applicationfiltercriteriapanel ---------- </ui:remove> <dti:dtipanel value="#{viewapplicationconfig.getpanelbean('applicationfiltercriteriapanel')}" toggleable="true" togglespeed="500"> <dti:dtilayer id="#{viewapplicationconfig.getlayer('applicationfiltercriterialayer').getlayerid()}"> <div style="width: 600px;"> <div style="float: left"> <h:datatable value="#{viewapplicationconfig.getlayerfields('applicationfiltercriterialayer')}" var="field"> <h:column> <dti:dtifield field="#{field}" record="#{record}"/> </h:column> </h:datatable> </div> </div> </dti:dtilayer> </dti:dtipanel> <ui:remove> ------ end applicationfiltercriteriapanel ---------- </ui:remove> <ui:remove> ------ applicationgridpanel ---------- </ui:remove> <dti:dtipanel value="#{viewapplicationconfig.getpanelbean('applicationgridpanel')}" toggleable="true" togglespeed="500"> <dti:dtilayer id="#{viewapplicationconfig.getlayer('applicationgridlayer_gh').getlayerid()}"> <div style="width: 600px;"> <div style="float: left"> <h:datatable value="#{viewapplicationconfig.getlayerfields('applicationgridlayer_gh')}" var="field"> <h:column> <dti:dtifield field="#{field}" record="#{record}"/> </h:column> </h:datatable> </div> </div> </dti:dtilayer> <ui:remove> ------ dti grid ---------- </ui:remove> <dti:dtigrid columns="#{viewapplicationconfig.getlayerfields('applicationgridlayer_gh')}" databean="#{viewapplicationconfig}"/> <ui:remove> ------ end dti grid ---------- </ui:remove> <ui:remove> ------ end applicationgridpanel ---------- </ui:remove> </dti:dtipanel> <ui:remove> ------ debugging code -------------- <h1 class="title ui-widget-header ui-corner-all" style="width: 1200px; margin-left: 20px;"><h:outputlabel value="welcome #{loginbean.name}"></h:outputlabel></h1> <h:outputtext value="theme: #{guestpreferences.theme}"/><br/> <h:outputtext value="selected contextapplicationid -- getcontextapplicationid(): #{viewapplicationconfig.contextapplicationid}"/> <br/> <h:outputtext value="grid header -- getxmlheader(): #{viewapplicationconfig.xmlheader}"/> <br/> <h:outputtext value="grid header fields -- getxmlheaderfields(): #{viewapplicationconfig.xmlheaderfields}"/> <br/> <h:outputtext value="grid header layer fields -- getxmlheaderlayerfields(): #{viewapplicationconfig.xmlheaderlayerfields}"/> <br/> <h:outputtext value="page fields -- getpagefields(): #{viewapplicationconfig.pagefields}"/> <br/> <h:outputtext value="layers getlayers(): #{viewapplicationconfig.layers}"/> <br/> <h:outputtext value="layers getlayer(applicationgridlayer_gh): #{viewapplicationconfig.getlayer('applicationgridlayer_gh')}"/> <br/> <h:outputtext value="layers getlayerfields(applicationgridlayer_gh): #{viewapplicationconfig.getlayerfields('applicationgridlayer_gh')}"/> <br/> <div class="entry"> <h:form> <h:commandlink actionlistener="#{viewapplicationconfig.navigatetopageconfig}" value="click on contextapplicationid"/> <p:datatable var="record" value="#{viewapplicationconfig.applications}" paginator="true" rows="5" id="entitytable" style="width:1220px"> <f:facet name="header"> applications -- size: #{viewapplicationconfig.applications.size()} </f:facet> <p:column headertext="clientid" style="width:100px"> <h:outputtext value="#{record.fieldnamelist}"/> </p:column> </p:datatable> </h:form> </div> ------ end debugging code ---------- </ui:remove> </p:panel> </ui:define> </ui:composition>
dtipanel.xhtml
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:composite="http://java.sun.com/jsf/composite"> <composite:interface> <composite:attribute name="value" required="true"/> <composite:attribute name="toggleable" required="true"/> <composite:attribute name="closable"/> <composite:attribute name="togglespeed"/> <composite:attribute name="collapsed"/> </composite:interface> <composite:implementation> <p:panel id="#{cc.attrs.value.id}" header="#{cc.attrs.value.title}" toggleable="#{cc.attrs.toggleable}" closable="#{cc.attrs.closable}" togglespeed="#{cc.attrs.togglespeed}" collapsed="#{cc.attrs.collapsed}"> <composite:insertchildren/> </p:panel> </composite:implementation> </html>
dtilayer.xhtml
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:composite="http://java.sun.com/jsf/composite"> <composite:interface> <composite:attribute name="id" required="true"/> <composite:attribute name="hidden"/> </composite:interface> <composite:implementation> <p:outputpanel id="#{cc.attrs.id}" rendered="#{!cc.attrs.hidden}"> <composite:insertchildren/> </p:outputpanel> </composite:implementation> </html>
dtigrid.xhtml
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:composite="http://java.sun.com/jsf/composite" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:dti="http://java.sun.com/jsf/composite/dti"> <composite:interface> <composite:attribute name="columns" required="true"/> <composite:attribute name="databean" required="true"/> </composite:interface> <composite:implementation> <div class="entry"> <h:form id="gridform"> <p:ajaxstatus style="width:32px;height:32px;"> <f:facet name="start"> <h:graphicimage value="/core/images/design/ajaxloading.gif"/> </f:facet> <f:facet name="complete"> <h:outputtext value=""/> </f:facet> </p:ajaxstatus> <f:facet name="header"> <p:messages/> </f:facet> <p:growl id="growl" showdetail="true"/> <h:panelgrid columns="2"> <p:panel header="export data"> <h:commandlink> <p:graphicimage value="/core/images/primefaces/excel.png"/> <p:dataexporter type="xls" target="entitytable" filename="entitydialog"/> </h:commandlink> <h:commandlink> <p:graphicimage value="/core/images/primefaces/pdf.png"/> <p:dataexporter type="pdf" target="entitytable" filename="entitydialog"/> </h:commandlink> <h:commandlink> <p:graphicimage value="/core/images/primefaces/csv.png"/> <p:dataexporter type="csv" target="entitytable" filename="entitydialog"/> </h:commandlink> <h:commandlink> <p:graphicimage value="/core/images/primefaces/xml.png"/> <p:dataexporter type="xml" target="entitytable" filename="entitydialog"/> </h:commandlink> </p:panel> <p:panel header="export page data"> <h:commandlink> <p:graphicimage value="/core/images/primefaces/excel.png"/> <p:dataexporter type="xls" target="entitytable" filename="entitydialog" pageonly="true"/> </h:commandlink> <h:commandlink> <p:graphicimage value="/core/images/primefaces/pdf.png"/> <p:dataexporter type="pdf" target="entitytable" filename="entitydialog" pageonly="true"/> </h:commandlink> <h:commandlink> <p:graphicimage value="/core/images/primefaces/csv.png"/> <p:dataexporter type="csv" target="entitytable" filename="entitydialog" pageonly="true"/> </h:commandlink> <h:commandlink> <p:graphicimage value="/core/images/primefaces/xml.png"/> <p:dataexporter type="xml" target="entitytable" filename="entitydialog" pageonly="true"/> </h:commandlink> </p:panel> </h:panelgrid> <p:datatable var="record" value="#{cc.attrs.databean.applications}" paginator="true" rows="5" id="entitytable" selection="#{cc.attrs.databean.selectedrecord}" selectionmode="single" rowselectlistener="#{cc.attrs.databean.onrowselect}" onrowselectupdate="rowform:display growl" rowunselectlistener="#{cc.attrs.databean.onrowunselect}" onrowunselectupdate="growl" onrowselectcomplete="rowdialog.show()" update="rowform:display" dblclickselect="true" style="width:1220px"> <f:facet name="header"> applications -- size: #{cc.attrs.databean.applications.size()} </f:facet> <c:foreach var="column" items="#{cc.attrs.columns}"> <c:choose> <c:when test="#{fn:touppercase(column.fieldid)=='select_ind_gh'}"> <p:column selectionmode="multiple" style="width:20px"/> </c:when> <c:otherwise> <p:column headertext="#{column.label}" filterby="#{record.getfieldvalue(fn:substringbefore(column.fieldid, '_gh'))}" sortby="#{record.getfieldvalue(fn:substringbefore(column.fieldid, '_gh'))}" style="width:100px"> <c:choose> <c:when test="#{not empty column.href}"> <h:link outcome="viewapplicationconfig" value="#{record.getfieldvalue(fn:substringbefore(column.fieldid, '_gh'))}"> <f:param name="pageurl" value="#{column.href}"/> </h:link> </c:when> <c:otherwise> <h:outputtext value="#{record.getfieldvalue(fn:substringbefore(column.fieldid, '_gh'))}"/> <ui:remove> <br/>field id: #{column.fieldid} <br/>data type: #{column.datatype} <br/>display type: #{column.displaytype} <br/>read only: #{column.isreadonly} <br/>visible: #{column.isvisible} <br/>href: #{column.href} </ui:remove> </c:otherwise> </c:choose> </p:column> </c:otherwise> </c:choose> </c:foreach> </p:datatable> </h:form> <p:dialog header="edit row" widgetvar="rowdialog" resizable="false" width="700"> <h:form id="rowform"> <dti:dtipanel id="display" value="#{viewapplicationconfig.getpanelbean('applicationgriddetailpanel')}" toggleable="true" togglespeed="500" collapsed="false"> <dti:dtilayer id="#{viewapplicationconfig.getlayer('applicationgriddetaillayer').getlayerid()}"> <div style="width: 600px;"> <div style="float: left"> <h:datatable value="#{viewapplicationconfig.getlayerfields('applicationgriddetaillayer')}" var="field"> <h:column> <ui:remove> <h:outputtext value="testx: #{cc.attrs.databean.selectedrecord.getfieldvalue('baseshortdescription')}"/> / <h:outputtext value="testx 1: #{cc.attrs.databean.selectedrecord.size}"/> </ui:remove> <dti:dtifield field="#{field}" record="#{cc.attrs.databean.selectedrecord}"/> </h:column> </h:datatable> </div> </div> </dti:dtilayer> </dti:dtipanel> </h:form> </p:dialog> </div> </composite:implementation> </html>
dtifield.xhtml
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:composite="http://java.sun.com/jsf/composite"> <composite:interface> <composite:attribute name="field" required="true"/> <composite:attribute name="record" type="dti.oasis.recordset.record" required="true"/> </composite:interface> <composite:implementation> <ui:remove> <h:outputtext value="fieldname 0: #{cc.attrs.record.getfieldnamelist().get(0)}"/> / <h:outputtext value="test 1: #{cc.attrs.record.size()}"/> </ui:remove> <p:outputpanel rendered="#{cc.attrs.field.isvisible , !fn:endswith(cc.attrs.field.fieldid, '_gh')}"> <div id="#{cc.clientid}"> <h:panelgrid columns="2"> <div style="width: 100%"> <div style="float: left; #{cc.attrs.field.style}"> #{cc.attrs.field.label} </div> <div style="float: right"> <h:outputtext value="#{cc.attrs.record.getfieldvalue(cc.attrs.field.fieldid)}" rendered="#{cc.attrs.field.isreadonly}"/> <h:inputtext rendered="#{cc.attrs.field.displaytype == 'text' , !cc.attrs.field.isreadonly}" value="#{cc.attrs.record.getfieldvalue(cc.attrs.field.fieldid)}"/> <h:selectonemenu rendered="#{cc.attrs.field.displaytype == 'select' , !cc.attrs.field.isreadonly}"> <f:selectitems/> </h:selectonemenu> <h:selectbooleancheckbox rendered="#{cc.attrs.field.displaytype == 'checkbox' , !cc.attrs.field.isreadonly}" value="#{cc.attrs.record.getfieldvalue(cc.attrs.field.fieldid)}"/> <ui:remove> <br/>display type: #{cc.attrs.field.displaytype} <br/>visible: #{cc.attrs.field.isvisible} <br/>read only: #{cc.attrs.field.isreadonly} <br/>field id: #{cc.attrs.field.fieldid} <br/>rows: #{cc.attrs.field.rownum} <br/>columns: #{cc.attrs.field.colnum} <br/>field value: #{cc.attrs.record.getfieldvalue(cc.attrs.field.fieldid)} </ui:remove> </div> </div> </h:panelgrid> </div> </p:outputpanel> </composite:implementation> </html>
the bean class looks following:
package com.dti.admin.cwb.appconfigmgr.view; import com.dti.admin.view.baseadminmanagedbean; import com.dti.view.managedbeanutils; import dti.admin.cwb.appconfigmgr.appconfigmanager; import dti.oasis.recordset.record; import dti.oasis.recordset.recordset; import org.primefaces.event.selectevent; import org.primefaces.event.unselectevent; import org.springframework.beans.factory.annotation.autowired; import org.springframework.context.annotation.scope; import org.springframework.stereotype.component; import javax.annotation.postconstruct; import javax.annotation.predestroy; import javax.faces.application.facesmessage; import javax.faces.context.facescontext; import javax.faces.event.actionevent; import javax.servlet.http.httpservletrequest; import java.io.serializable; import java.util.list; @component("viewapplicationconfig") @scope("request") public class viewapplicationconfig extends baseadminmanagedbean implements serializable { private appconfigmanager appconfigmanager; private string contextapplicationid; private list<record> applications; private recordset applicationrecordset; ////// private record selectedrecord; public record getselectedrecord() { system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- getselectedrecord --"); if(selectedrecord!=null){ system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- getselectedrecord -- getrecordnumber: "+ selectedrecord.getrecordnumber()); } return selectedrecord; } public void setselectedrecord(record selectedrecord) { this.selectedrecord = selectedrecord; } ////// public void onrowselect(selectevent event) { system.out.println("onrowselect"); facesmessage msg = new facesmessage("entity selected", (string)((record) event.getobject()).getfieldvalue("baseshortdescription")); facescontext.getcurrentinstance().addmessage(null, msg); } public void onrowunselect(unselectevent event) { system.out.println("onrowunselect"); facesmessage msg = new facesmessage("entity unselected", (string)((record) event.getobject()).getfieldvalue("baseshortdescription")); facescontext.getcurrentinstance().addmessage(null, msg); } /////////////////// public viewapplicationconfig() { system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- " + "viewapplicationconfig()"); } @autowired() public viewapplicationconfig(appconfigmanager appconfigmanager) { system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- " + "viewapplicationconfig(appconfigmanager appconfigmanager)"); this.appconfigmanager = appconfigmanager; this.setpageid("maintainapplicationconfig"); this.setanchorcolumnname("applicationid"); } @postconstruct public void onload() throws exception { system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- " + "onload()"); httpservletrequest request = managedbeanutils.gethttpservletrequest(); init(request); //grid header setxmlheader(getgridheader(request)); //from action class record inputrecord = getinputrecord(request); //from prime-movicollector -- sort of if(applicationrecordset == null) { applicationrecordset = appconfigmanager.loadallwebapplications(inputrecord); applications = managedbeanutils.convertrecordsettolist(applicationrecordset); } // system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " + applications.size()); } @predestroy public void onunload() { system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- " + "onunload()"); terminate(); } public void navigatetopageconfig(actionevent actionevent) { system.out.println("navigatetopageconfig("+contextapplicationid+")"); string pageurl = "/pageconfigmgr/maintainpageconfig.do?contextapplicationid=" + contextapplicationid; navigatetopage(pageurl); } public appconfigmanager getappconfigmanager() { return appconfigmanager; } public void setappconfigmanager(appconfigmanager appconfigmanager) { this.appconfigmanager = appconfigmanager; } public list<record> getapplications() { system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- " + "getapplications()"); return applications; } public void setapplications(list <record> applications) { system.out.println(new java.sql.timestamp(system.currenttimemillis()) + " -- " + this.getclass().getname() + " -- " + "setapplications(recordset applications)"); this.applications = applications; } public recordset getapplicationrecordset() { return applicationrecordset; } public void setapplicationrecordset(recordset applicationrecordset) { this.applicationrecordset = applicationrecordset; } public string getcontextapplicationid() { return contextapplicationid; } public void setcontextapplicationid(string contextapplicationid) { this.contextapplicationid = contextapplicationid; } }
did have similar issue using composite components, p:datatable , p:dialog?
i didn't read through whole code didn't point me specific piece of code "when click <p:commandbutton id="somebutton"
..." i'm 'taking guess'.
i see backing bean request scoped using spring's container. think problem you're experiencing bean has lifespan of 1 request. if you're doing ajax things selecting rows in data table need view scoped bean. have @ this question explanation of different scopes.
i'm guessing want use view scoped bean, , know spring doesn't have @scope("view")
can use. luckily cagatay civici came rescue , has posted a solution on blog.
Comments
Post a Comment