Exposing composite component attribute to children - jsf-2

I have the necessity to load some data in a dataTable using lazy loading. Unfortunatelly, primefaces dataTable only suports lazy loading with pagination, but this is unacceptable to this project, so I created and tested some mechanisms to permit lazy loading in datatable using scroll (primefaces's liveScroll isn't lazy loading). Now I need to move these mechanisms to a composite component, so I decided to wrap primefaces dataTable:
<ui:component xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.prime.com.tr/ui">
<c:interface>
<c:attribute name="var" required="true" targets="tabela"/>
<c:attribute name="value" required="true" targets="tabela" type="java.util.List"/>
<c:attribute name="scrollable" targets="tabela"/>
<c:attribute name="liveScroll" required="false" default="false"/>
<c:attribute name="height" targets="tabela"/>
<c:attribute name="emptyMessage" targets="tabela" default="Nenhuma dado a ser exibido"/>
<c:attribute name="rows" targets="tabela"/>
<c:attribute name="action" method-signature="void method()" required="false"/>
</c:interface>
<c:implementation>
<div id="#{cc.clientId}">
<p:dataTable id="tabela" var="#{cc.attrs.var}" value="#{cc.attrs.value}"
scrollable="#{scrollable}" height="#{cc.attrs.height}"
emptyMessage="#{cc.attrs.emptyMessage}" rows="10">
<c:insertChildren/>
</p:dataTable>
<p:remoteCommand name="comandoAtualizarTabela" action="#{cc.attrs.action}" update="tabela" process="#none"/>
<script type="text/javascript">
if ("#{cc.attrs.liveScroll}") {
var idEscapadoPainelLista = PrimeFaces.escapeClientId("#{cc.clientId}");
jQuery(idEscapadoPainelLista).find(".ui-datatable-scrollable-body").scroll(function () {
if ((this.scrollTop == this.scrollHeight - this.clientHeight))
comandoAtualizarTabela();
});
}
</script>
</div>
</c:implementation>
</ui:component>
When I try to use this component, no data is showed in the rows cause of this exception:
[#|2012-07-12T09:34:10.010-0300|SEVERE|glassfish3.1.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-10;|org.apache.myfaces.view.facelets.el.ContextAwarePropertyNotFoundException: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getType(ContextAwareTagValueExpression.java:79)
at org.primefaces.component.inputtext.InputTextRenderer.getConvertedValue(InputTextRenderer.java:113)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:647)
at javax.faces.component.UIInput.validate(UIInput.java:583)
at javax.faces.component.UIInput.processValidators(UIInput.java:273)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1317)
at javax.faces.component.UIData.process(UIData.java:1919)
at javax.faces.component.UIData.processColumnChildren(UIData.java:1904)
at javax.faces.component.UIData.processValidators(UIData.java:1761)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1317)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1317)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIForm.processValidators(UIForm.java:209)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1324)
at javax.faces.component.UIViewRoot._processValidatorsDefault(UIViewRoot.java:1350)
at javax.faces.component.UIViewRoot.access$500(UIViewRoot.java:74)
at javax.faces.component.UIViewRoot$ProcessValidatorPhaseProcessor.process(UIViewRoot.java:1443)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1306)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:793)
at org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at fr.xebia.servlet.filter.ExpiresFilter.doFilter(ExpiresFilter.java:1243)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:109)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.gr|#]
[#|2012-07-12T09:34:10.011-0300|SEVERE|glassfish3.1.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=21;_ThreadName=Thread-10;|izzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:131)
at com.sun.el.parser.AstValue.getType(AstValue.java:76)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:195)
at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getType(ContextAwareTagValueExpression.java:75)
... 90 more|#]
ADDED
The application uses spring version 3.0.7. Once the application have more than 20 spring xml files, I'm showing just part of one spring file... This part configures the dialog I'm testing with the composite component:
<bean id="controladorPopupCadastroUnidade" class="com.hrgi.web.cadastro.controladores.popups.ControladorPopupCadastroUnidade" scope="request">
<property name="controladorArmazenamento" ref="controladorArmazenamentoUnidade"/>
<property name="conversorValor" ref="conversorUnidade"/>
<property name="modelo" ref="modeloPopupCadastroUnidade"/>
<property name="popupAlerta" ref="controladorPopupAlerta"/>
<property name="recuperadorValores" ref="unidadeDao"/>
<property name="popupConfirmacao" ref="controladorPopupConfirmacao"/>
</bean>
<bean id="modeloPopupCadastroUnidade" class="com.hrgi.web.ui.modelos.ModeloPopupCRUD" scope="session">
<property name="visivel" value="false"/>
<property name="mensagemSucesso" value="${gerais.lista.sucesso}" />
</bean>
<bean id="controladorArmazenamentoUnidade" class="com.hrgi.persistencia.controladores.ControladorArmazenamento" scope="request">
<property name="armazenador" ref="unidadeDao"/>
<property name="atualizador" ref="unidadeDao"/>
<property name="removedor" ref="unidadeDao"/>
<property name="conversor" ref="conversorUnidade"/>
</bean>
to help you see the problem, here is the dataTable part of xhtml file I'm trying use teh cc:
<h:panelGroup id="painelLista" layout="block" styleClass="clearfix">
<hrgi:dataTable var="bean" value="#{modeloPopupCadastroUnidade.lista}"
scrollable="true" height="145"
action="#{controladorPopupCadastroUnidade.atualizarValores}"
liveScroll="true" rows="10">
<p:column headerText="Nome" style="width: 23%">
<hrgi:cellEditor>
<f:facet name="saida">
<h:outputText value="#{bean.descricao}"/>
</f:facet>
<f:facet name="entrada">
<p:inputText value="#{bean.descricao}" maxlength="35" style="width: 90%"/>
</f:facet>
</hrgi:cellEditor>
</p:column>
<p:column headerText="Sigla">
<hrgi:cellEditor>
<f:facet name="saida">
<h:outputText value="#{bean.sigla}"/>
</f:facet>
<f:facet name="entrada">
<p:inputText value="#{bean.sigla}" maxlength="5"/>
</f:facet>
</hrgi:cellEditor>
</p:column>
<p:column headerText="Fator" sortBy="#{bean.fator}">
<hrgi:cellEditor>
<f:facet name="saida">
<h:outputText value="#{bean.fator}"/>
</f:facet>
<f:facet name="entrada">
<hrgi:spinner value="#{bean.fator}" dinheiro="false" fator="1" local="pt-BR" width="40"/>
</f:facet>
</hrgi:cellEditor>
</p:column>
<p:column headerText="Fracionado" sortBy="#{bean.fracionado}">
<hrgi:cellEditor>
<f:facet name="saida">
<h:outputText value="#{bean.fracionado eq true?'Sim':'Não'}"/>
</f:facet>
<f:facet name="entrada">
<h:selectBooleanCheckbox value="#{bean.fracionado}"/>
</f:facet>
</hrgi:cellEditor>
</p:column>
<p:column headerText="Unitário" sortBy="#{bean.unitario}">
<hrgi:cellEditor>
<f:facet name="saida">
<h:outputText value="#{bean.unitario eq true?'Sim':'Não'}"/>
</f:facet>
<f:facet name="entrada">
<h:selectBooleanCheckbox value="#{bean.unitario}"/>
</f:facet>
</hrgi:cellEditor>
</p:column>
<p:column>
<hrgi:rowEditor action="#{controladorPopupCadastroUnidade.editarValor(bean)}" update="alerta" indice="#{bean.indice}"/>
<p:commandLink title="#{msgGerais['gerais.excluir']}" action="#{controladorPopupCadastroUnidade.removerValor(bean)}" update="painelLista alerta confirmacao" immediate="true">
<h:graphicImage library="img" name="remover.png"/>
</p:commandLink>
</p:column>
</hrgi:dataTable>
</h:panelGroup>
Probably the problem is that var property can't be used outside composite component... Is there a way I can expose this attribute externally? How can I solve it?

Related

Primefaces datatable filtering not working [duplicate]

This question already has an answer here:
java.lang.NullPointerException at org.primefaces.component.datatable.feature.FilterFeature.filter
(1 answer)
Closed 6 years ago.
I'm trying to make a table filter using Primefaces 5,
but the filtering dosn't occur and get the follow stack:
java.lang.NullPointerException at
org.primefaces.component.datatable.feature.FilterFeature.filter(FilterFeature.java:136)
at
org.primefaces.component.datatable.feature.FilterFeature.encode(FilterFeature.java:105)
at
org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:77)
at
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
at
com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)
at
com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:692) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1740) at
javax.faces.component.UIComponent.visitTree(UIComponent.java:1740) at
com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)
at
com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:319)
at
org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at
javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896)
at
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:425)
at
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.star.AuthFilter.doFilter(AuthFilter.java:42) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I'm cloning the primefaces showcase example but i'm not getting it right!
here is my code:
xhtml file:
<p:dataTable id="tbl" var="sim" value="#{simulationLog.simulation}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
paginator="true" rows="10" style="margin-bottom:20px"
filteredValue="#{simulationLog.filtredSimulation}"
>
<p:column filterBy="#{sim.simId}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<p:commandLink value="#{sim.simId}" />
</p:column>
backing bean:
#ManagedBean
#SessionScoped
public class SimulationLog implements Serializable {
.
.
.
private List<SimulationLog> simulation;
private List<SimulationLog> filtredSimulation;
public List<SimulationLog> getSimulation() {
return ParamsDAO.getSimulation(codeAgence);
}
public List<SimulationLog> getFiltredSimulation() {
return filtredSimulation;
}
public void setFiltredSimulation(List<SimulationLog> filtredSimulation) {
this.filtredSimulation = filtredSimulation;
}
.
.
.
}
I had the same error and could fix it by wrapping the dataTable with a <h:form>.
In short, I had the following and was causing the same error:
<f:facet name="header">Date</f:facet>
<f:facet name="filter">
<h:outputText value="Year: " />
<p:selectOneMenu onchange="PF('myTable').filter();">
<f:selectItem itemValue="" itemLabel="All" />
<f:selectItems value="#{bean.conditionalYears}" var="yearSelect" itemValue="#{yearSelect.value}" itemLabel="#{yearSelect.label}" />
</p:selectOneMenu>
</f:facet>
I had to remove everything from <f:facet name="filter" /> except the <p:selectOneMenu />
In my case, the <h:outputText /> (not limited to outputText) was causing ClassCastException in FilterFeature:277 that were swallowed by UIData.visitTree(VisitContext, VisitCallback) (doesn't have CATCH)
filterValue = ((ValueHolder) filterFacet).getLocalValue();
For some reason, filterFacet is an UIPanel, not a SelectOneMenu as expected.
So, the answer is:
If you are using <f:facet name="filter" />, then try removing everything from it except your custom filter field.

primefaces datatable row select not working after filtering or sorting

I have a problem with primefaces datatable which implements filtering and sorting and select rows (like complex datatable in primefaces showcases), when I sort or filter in datatable, SelectedElement resolve to null if I select a row, but if I choose a row without filtering or sorting, select event work perfectly.
My 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.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Liste des Prospects</title>
<style type="text/css">
</style>
</h:head>
<h:body>
<p:layout style="min-width:900px;min-height:400px;" id="layout" fullPage="true">
<p:layoutUnit size="50" position="north" ><ui:include src="/Menus.xhtml" /></p:layoutUnit>
<h:form id="form">
<p:layoutUnit position="center" size="230" resizable="false" closable="true" collapsible="true">
<p:layout>
<p:layoutUnit position="center">
<p:dataTable id="cars" scrollable="true" frozenColumns="4"
selection="#{prospectBean.selectedProspect}" selectionMode="single" stickyHeader="false" var="listd"
sortMode="single" widgetVar="ProspectTable" value="#{prospectBean.list}" rowKey="#{listd.idProspect}"
emptyMessage="Pas de prospects avec ces critères" rowSelectMode="single" filteredValue="#{prospectBean.filteredProspects}">
<p:ajax event="rowSelect" listener="#{prospectBean.onRowSelect}" update=":form:Agenda" />
<p:ajax event="rowUnselect" listener="#{prospectBean.onRowUnSelect()}"/>
<p:ajax event="filter" update=":form:cars" />
<f:facet name="header" >
<p:outputPanel >
<h:outputText style="width:150px;" value="Chercher dans tous les camps:" />
<p:inputText id="globalFilter" onkeyup="PF('ProspectTable').filter()" style="width:150px;" placeholder="Enter keyword"/>
<p:commandButton action="#{prospectBean.AjouterProspect()}" style="width:12%;float: left;height:8%" ajax="false" icon="ui-icon-circle-plus" />
</p:outputPanel>
</f:facet>
<p:column width="14" >
<p:commandButton action="#{prospectBean.ModifierProspect(listd)}" style="width:15px;height:15px" ajax="false" icon="ui-icon-pencil"/>
</p:column>
<p:column width="140" sortBy="#{listd.raisonsociale}" headerText="Raison Sociale" filterBy="#{listd.raisonsociale}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.raisonsociale}"/>
</p:column>
<p:column width="140" sortBy="#{listd.raisonsocialeabrg}" headerText="RS Abrégé" filterBy="#{listd.raisonsocialeabrg}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.raisonsocialeabrg}"/>
</p:column>
<p:column width="140" sortBy="#{listd.telephone}" headerText="Téléphone" filterBy="#{listd.telephone}" filterStyle="display:none">
<h:outputText value="#{listd.telephone}"/>
</p:column>
<p:column width="140" sortBy="#{listd.telephone2}" headerText="Téléphone 2" filterBy="#{listd.telephone2}" filterStyle="display:none">
<h:outputText value="#{listd.telephone2}"/>
</p:column>
<p:column width="140" sortBy="#{listd.fax}" headerText="Fax" filterBy="#{listd.fax}" filterStyle="display:none">
<h:outputText value="#{listd.fax}"/>
</p:column>
<p:column width="190" sortBy="#{listd.siteWeb}" headerText="Site Web" filterBy="#{listd.siteWeb}" filterStyle="display:none">
<h:outputText value="#{listd.siteWeb}"/>
</p:column>
<p:column width="190" sortBy="#{listd.email}" headerText="Email" filterBy="#{listd.email}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.email}"/>
</p:column>
<p:column width="140" sortBy="#{listd.ville}" headerText="Ville" filterBy="#{listd.ville}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.ville}"/>
</p:column>
<p:column width="140" sortBy="#{listd.pays}" headerText="Pays" filterBy="#{listd.pays}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText value="#{listd.pays}"/>
</p:column>
<p:column width="140" sortBy="#{listd.chiffreaffaire}" headerText="Chiffre d'affaire" filterBy="#{listd.chiffreaffaire}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.chiffreaffaire}"/>
</p:column>
<p:column width="140" sortBy="#{listd.activite}" headerText="Activite" filterBy="#{listd.activite}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.activite}"/>
</p:column>
<p:column width="140" sortBy="#{listd.secteur}" headerText="Secteur" filterBy="#{listd.secteur}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.secteur}"/>
</p:column>
<p:column width="140" sortBy="#{listd.statut.denomination}" headerText="Statut" filterBy="#{listd.statut.denomination}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText value="#{listd.statut.denomination}"/>
</p:column>
</p:dataTable>
</p:layoutUnit>
<p:layoutUnit position="south" size="322" resizable="false" closable="true" collapsible="true">
<p:dataTable id="Agenda" scrollable="false" filteredValue="#{AgendaBean.filteredAgenda}"
selectionMode="single" var="lista" sortMode="single"
widgetVar="AgendaTable" value="#{AgendaBean.list}" rowKey="#{lista.id}"
emptyMessage="Pas d'événement avec ces critères" >
<f:facet name="header" >
<p:outputPanel >
<h:outputText style="width:150px;" value="Chercher dans tous les camps:" />
<p:inputText id="globalFilter" onkeyup="PF('AgendaTable').filter()" style="width:150px;" placeholder="Enter keyword"/>
<p:commandButton action="#{AgendaBean.AjouterAgenda()}" rendered="#{prospectBean.checked}" style="width:12%;height:6%;float: left;" ajax="false" icon="ui-icon-circle-plus" />
</p:outputPanel>
</f:facet>
<p:column width="17" >
<p:commandButton action="#{AgendaBean.ModifierAgenda(lista)}" style="width:15px; height:17px" ajax="false" icon="ui-icon-pencil"/>
</p:column>
<p:column sortBy="#{lista.dateHeure}" width="170" headerText="Date Heure" filterBy="#{lista.dateHeure}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText id="id01" value="#{lista.dateHeure}"/>
</p:column>
<p:column sortBy="#{lista.natureevenement.libelle}" headerText="Nature" filterBy="#{lista.natureevenement.libelle}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText id="id11" value="#{lista.natureevenement.libelle}"/>
</p:column>
<p:column sortBy="#{lista.intervenant.nom}" headerText="Intervenant" filterBy="#{lista.intervenant.nom}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText id="id21" value="#{lista.intervenant.nom}"/>
</p:column>
<p:column sortBy="#{lista.statut.denomination}" headerText="Statut" filterBy="#{lista.statut.denomination}" filterMatchMode="contains" filterStyle="display:none" >
<h:outputText id="id31" value="#{lista.statut.denomination}"/>
</p:column>
<p:column sortBy="#{lista.duree}" width="70" headerText="Duree" filterBy="#{lista.duree}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText id="id41" value="#{lista.duree}"/>
</p:column>
<p:column sortBy="#{lista.lieu}" width="170" headerText="Lieu" filterBy="# {lista.lieu}" filterMatchMode="contains" filterStyle="display:none">
<h:outputText id="id61" value="#{lista.lieu}"/>
</p:column>
</p:dataTable>
</p:layoutUnit>
</p:layout>
</p:layoutUnit>
</h:form>
</p:layout>
</h:body>
</html>
MyBean
#ManagedBean(name="prospectBean")
#SessionScoped
public class ProspectBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
....
public void onRowSelect(SelectEvent se)
{
setProspect(getSelectedProspect());
agendabean.setProspect(getSelectedProspect());
checked=true;
try{
AgendaBean.AfficherAgendas(getProspect());
}catch(Exception e){e.printStackTrace();}
System.out.print("ca marche encore");
}
public void onRowUnSelect(SelectEvent se)
{
checked=false;
}
//agendabean.setProspect(getSelectedProspect()); resolve to null pointer exception
java.lang.NullPointerException
at Interface.AgendaBean.AfficherAgendas(AgendaBean.java:508)
at Interface.ProspectBean.onRowSelect(ProspectBean.java:775)

<p:datatable> partial process does not reflect changes immediately

I have a code like:
<p:dataTable style="padding-top: 5px" var="leaveDetails" value="#{userLeaveBean.leaveDetails}" id="leaveDataTable" editable="true">
<p:column headerText="Leave Starts on" width="230">
<p:calendar valueChangeListener="#{userLeaveBean.handleFromDateChanege}" value="#{leaveDetails.dtLeaveFromDate}" pattern="dd-MMM-yyyy" size="16" showOn="button" id="editFrom">
<p:ajax event="dateSelect"/>
</p:calendar>
<h:selectOneRadio value="#{leaveDetails.strStartTiming}" valueChangeListener="#{userLeaveBean.handleRadioFirstValueChange}">
<f:selectItem itemValue="morning" itemLabel="Morning"/>
<f:selectItem itemValue="afternoon" itemLabel="Afternoon" />
<p:ajax event="click"/>
</h:selectOneRadio>
</p:column>
<p:column headerText="Leave Ends on" width="230">
<p:calendar valueChangeListener="#{userLeaveBean.handleToDateChanege}" value="#{leaveDetails.dtLeaveToDate}" pattern="dd-MMM-yyyy" size="16" showOn="button" id="editTo">
<p:ajax event="dateSelect"/>
</p:calendar>
<h:selectOneRadio value="#{leaveDetails.strEndTiming}" valueChangeListener="#{userLeaveBean.handleRadioSecondValueChange}">
<f:selectItem itemValue="noon" itemLabel="Noon"/>
<f:selectItem itemValue="endofday" itemLabel="End Of Day"/>
<p:ajax event="click"/>
</h:selectOneRadio>
</p:column>
<p:column headerText="Days" width="40" id="total">
<h:outputText value="#{leaveDetails.totalLeaveDays}"/>
</p:column>
<p:column headerText="Creation" width="100">
<h:outputText value="#{leaveDetails.dtApplicationDate}">
<f:convertDateTime pattern="EEEE,dd-MMM-yyyy"/>
</h:outputText>
</p:column>
<p:column headerText="Status" width="100">
<h:outputText value="#{leaveDetails.strLeaveStatus}"/>
</p:column>
<p:column headerText="Edit" width="40" rendered="#{leaveDetails.strLeaveStatus == 'Canceled' or leaveDetails.strLeaveStatus == 'Availed'}">
<p:commandLink actionListener="#{userLeaveBean.editAppliedLeave}" title="Edit" disabled="true" update="leaveDataTable" immediate="true" partialSubmit="true">
<h:graphicImage url="resources/images/edit.JPG"/>
<f:attribute name="userId" value="#{employee.name}"/>
<f:attribute name="editFirstHalf" value="#{leaveDetails.strStartTiming}"/>
<f:attribute name="editSecondHalf" value="#{leaveDetails.strEndTiming}"/>
<f:attribute name="editFrom" value="#{leaveDetails.dtLeaveFromDate}"/>
<f:attribute name="editTo" value="#{leaveDetails.dtLeaveToDate}"/>
<f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
</p:commandLink>
</p:column>
<p:column headerText="Edit" width="40" rendered="#{leaveDetails.strLeaveStatus != 'Canceled'}">
<p:commandLink actionListener="#{userLeaveBean.editAppliedLeave}" title="Edit" disabled="false" update="leaveDataTable" immediate="true" process="#this" >
<h:graphicImage url="resources/images/edit.JPG"/>
<f:attribute name="userId" value="#{employee.name}"/>
<f:attribute name="editFirstHalf" value="#{leaveDetails.strStartTiming}"/>
<f:attribute name="editSecondHalf" value="#{leaveDetails.strEndTiming}"/>
<f:attribute name="editFrom" value="#{leaveDetails.dtLeaveFromDate}"/>
<f:attribute name="editTo" value="#{leaveDetails.dtLeaveToDate}"/>
<f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
</p:commandLink>
</p:column>
<p:column headerText="Cancel" width="60" rendered="#{leaveDetails.strLeaveStatus == 'Canceled' or leaveDetails.strLeaveStatus == 'Availed'}">
<p:commandLink actionListener="#{userLeaveBean.cancelForLeave}" title="Cancel Request" disabled="true" process="#this" update="leaveDataTable" immediate="false">
<h:graphicImage url="resources/images/cancel.gif"/>
<f:attribute name="userId" value="#{employee.name}"/>
<f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
</p:commandLink>
</p:column>
<p:column headerText="Cancel" width="60" rendered="#{leaveDetails.strLeaveStatus != 'Canceled'}">
<p:commandLink actionListener="#{userLeaveBean.cancelForLeave}" title="Cancel Request" disabled="false" process="#this" update="leaveDataTable" immediate="false" ajax="true">
<h:graphicImage url="resources/images/cancel.gif"/>
<f:attribute name="userId" value="#{employee.name}"/>
<f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
</p:commandLink>
</p:column>
</p:dataTable>
This part of code is written in a <p:datatable>.That means Row operation of a <p:datatable>.On clicking the <p:commandLink> some execution is happened, and I want it to reflect on the <p:datatable> immediatley. But it does not happen.
If I refresh the page, then the changes reflects for the row of the <p:datatable>. How can I modify my code to reflect the changes immediately.
Working on JSF2.0, primefaces 3.4.2, Jboss As7.1.1final and JDK6.0.
Bean is in #ViewScoped.
Please suggest.
Thanks in advance.

Filter is preventing to reset table values

The two main components in my jsf are p:tree and p:dataTable
The idea is to create a table according to the tree node selection.
Jsf:
<h:panelGrid columns="2" style="width: 100%" columnClasses="treeColumn,tableColumn">
<h:panelGroup id="treePanel">
<p:tree id="tree"
value="#{genRepBean.root}"
var="node"
dynamic="true"
cache="true"
animate="true"
selectionMode="single"
selection="#{genRepBean.selectedNode}"
rendered="#{genRepBean.renderTree}">
<p:ajax event="select" listener="#{genRepBean.onNodeSelect}" update=":mainForm:tablePanel"/>
<p:treeNode expandedIcon="ui-icon-folder-open"
collapsedIcon="ui-icon-folder-collapsed">
<h:outputText value="#{node.name}" styleClass="tableTreeText"/>
</p:treeNode>
<p:treeNode type="au" icon="ui-icon-document">
<h:outputText value="#{node.name}" />
</p:treeNode>
</p:tree>
</h:panelGroup>
<h:panelGroup id="tablePanel">
<p:dataTable id="acqDataTable"
var="acq"
value="#{genRepBean.acqList}"
rendered="#{genRepBean.renderTable}"
filteredValue="#{genRepBean.filteredAcqList}"
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15"
rows="10"
lazy="false"
style="width: 100%">
<p:column headerText="ID" sortBy="#{acq.Id}" styleClass="tableTreeText">
<h:outputText value="#{acq.Id}" />
</p:column>
<p:column headerText="IP ADDRESS" sortBy="#{acq.ipAddress}" styleClass="tableTreeText">
<h:outputText value="#{acq.ipAddress}"/>
</p:column>
<p:column headerText="STEP" sortBy="#{acq.Step}" filterBy="#{acq.Step}" filterMatchMode="contains" styleClass="tableTreeText">
<h:outputText value="#{acq.Step}"/>
</p:column>
<p:column headerText="STATUS" sortBy="#{acq.status}" filterBy="#{acq.status}" styleClass="tableTreeText">
<h:outputText value="#{acq.status}"/>
</p:column>
</p:dataTable>
The bean (onNodeSelect):
public void onNodeSelect() {
acqList.clear();
this.acqList = AcqHelper.getAllViaStartDate(new java.sql.Date(startDate.getTime()));
if (!acqList.isEmpty()) {
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("mainForm:acqDataTable");
dataTable.reset();
renderTable = true;
}
I don’t want to remove the filter option since its very usable to the client but I don’t know why its blocking the table refresh ??
Any help would be great
Thanks
You don't need to perform changes into a DataTable model. Primefaces is taking data from #{genRepBean.acqList}. Just set proper values in that list and reset #{genRepBean.filteredAcqList} list. After the request is completed, datatable will be refreshed with new values.

Dropdown's valueChangeListener not working with primefaces datatable

I have datatable and a dropdown within a xhtml. If I am deleting p:datatable code within this page then I am able to call the valueChangeListener of dropdown , but if p:datatable is present in xhtml, then I am not able to call it.
Xhtml code is
<ui:define name="content">
<f:view>
<h:form id="accountSummaryForm" prependId="false">
<h:selectBooleanCheckbox id="checkbox" value="true" />
<h:outputLabel value="Show certificates preview on sumit"></h:outputLabel>
<h:outputLabel value="Show certificates preview on sumit"></h:outputLabel>
<h:outputText align="left"
value="Value is #{reqSummaryHandler.certNumber}" />
<p:dataTable id="reqActList" paginatorAlwaysVisible="true"
var="reqInfo" value="#{reqSummaryHandler.certActListModel}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginator="true" rows="#{label.accountList_defaultNumberOfRows}"
selectionMode="single"
rowsPerPageTemplate="#{label.accountList_numberOfRows}" width="60%">
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="#{label.certNumber}" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.certNumber}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Version" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.certVersionNbrString}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Insured" />
</f:facet>
<ui:repeat value="#{reqInfo.clientList}" var="insuredInfo">
<h:outputText align="left"
value="#{insuredInfo.generalPartyInfo.nameInfo.commName.commercialName}" />
</ui:repeat>
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Certificate Holder" />
</f:facet>
<ui:repeat value="#{reqInfo.certificateHolderInfoList}"
var="certHoldInfo">
<h:outputText align="left"
value="#{certHoldInfo.additionalInterest.generalPartyInfo.nameInfo.commName.commercialName}" />
</ui:repeat>
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Activity Performed" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.effectiveTypeCd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Certificate Status" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.statusCd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Third Party" />
</f:facet>
<h:outputText align="left"
value="#{reqInfo.certWordingEndorsementInd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Manual Form" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.manualEntryInd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Manual Addendum" />
</f:facet>
<h:outputText align="left" value="#{reqInfo.mnlAddendumInd}" />
</p:column>
<p:column style="text-align:center;" filterBy="" sortBy=""
width="5%">
<f:facet name="header">
<h:outputLabel value="Path" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText align="left" value="#{reqInfo.routePathCd}"
readonly="true" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{reqInfo.routePathCd}">
<f:selectItem itemLabel="Issue Distribute" itemValue="A" />
<f:selectItem itemLabel="Send to Underwriter" itemValue="B" />
<f:selectItem itemLabel="Issue Do Not Distribute"
itemValue="C" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
<p:rowEditor rendered="#{reqInfo.statusCd eq 'A'}" />
</p:column>
<p:column style="text-align:center;white-space: normal;nowrap">
<f:facet name="header">
<h:outputLabel value="Action" />
</f:facet>
<ui:repeat value="#{reqInfo.availableFunctions.functionNameArray}"
var="linkInfo">
<p:commandLink id="View" value="#{linkInfo}" ajax="false" />
<br />
</ui:repeat>
</p:column>
</p:dataTable>
<p:spacer width="50" height="0"></p:spacer>
<p:spacer width="50" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<p:spacer width="3" height="0"></p:spacer>
<h:outputLabel value="Assign Path" style="font-weight:bold" />
<p:spacer width="5" height="10" />
<h:selectOneMenu id="dropdown2"
valueChangeListener="#{reqSummaryHandler.DoPathProcessing1}"
value="#{reqSummaryHandler.certNumber}" onchange="submit();">
<f:selectItem itemLabel="Issue Distribute" itemValue="A" />
<f:selectItem itemLabel="Send to Underwriter" itemValue="B" />
<f:selectItem itemLabel="Issue Do Not Distribute" itemValue="C" />
</h:selectOneMenu>
</h:form>
</f:view>
</ui:define>
And listener code is
public void DoPathProcessing1(ValueChangeEvent event) {
String newValue = (String) event.getNewValue();
System.out.println("Path"
+ certActListModel.getRowData().getRoutePathCd());
certActListModel.getRowData().setRoutePathCd(newValue);
System.out.println("value is " + newValue);
}
Any idea why it is not working?
I am using jsf-api-2.0.3 and primefaces-2.2.1
You are using both the value and the valueChangeListener attributes of the drop down component. Why would you do this?
Just having value="#{reqSummaryHandler.certNumber} will call setCertNumber(String certNumber) in your managed bean. Why not just put this code into the setter method?

Resources