0
I am implementing a selection list (Datatable) but I only get this error: Datamodel must implement org.primefaces.model.Selectabledatamodel when Selection is enabled.
Follow the code below:
<p:dataTable value="#{vendaControle.listaDeVendas}" id="tabela"
rendered="#{vendaControle.tipoBusca != 'item'}"
rowStyleClass="#{item.cancelada eq true ? 'lineColor' : null}"
selection="#{vendaControle.venda}"
selectionMode="single"
rowKey="#{venda.id}"
emptyMessage="Não há registros!" paginator="false"
scrollable="true" scrollHeight="410" var="venda" style="text-align: left">
<p:column headerText="Código" filterBy="#{venda.id}" width="80" filterStyle="max-width: 70px;">
#{venda.id}
</p:column>
<p:column headerText="Empresa" rendered="#{fazendaControle.listaFazendas.size() gt 1}" width="150" filterBy="#{venda.empresa.nome}" filterStyle="max-width: 70px;">
#{venda.empresa.nome}
</p:column>
<p:column headerText="Cliente" filterBy="#{venda.pessoa.nome}" width="350" filterStyle="width: 200px;">
#{venda.pessoa.nome}
</p:column>
<p:column headerText="Horário" width="50">
<h:outputText value="#{venda.dtVendaTela}">
<f:convertDateTime pattern="HH:mm"/>
</h:outputText>
</p:column>
<p:column headerText="Tipo" width="200">
<h:outputText value="#{venda.tipoDeVenda}"/>
</p:column>
<p:column headerText="Fiscal" width="80">
<h:outputText value="#{venda.codNfe}" rendered="#{venda.fiscal eq true and venda.codNfe != null}"/>
<h:outputText value="#{venda.codNfce}" rendered="#{venda.fiscal eq true and venda.codNfce != null}"/>
</p:column>
<p:column headerText="Vendedor" filterBy="#{venda.nomeFun}" width="250" filterStyle="width: 130px;">
<h:outputText value="#{venda.nomeFun}"/>
</p:column>
<p:column headerText="Total (R$)" style="text-align: right" width="100">
<h:outputText value="#{venda.totalDesc}">
<f:convertNumber minFractionDigits="2"
maxFractionDigits="2"
/>
</h:outputText>
</p:column>
</p:dataTable>
<p:contextMenu for="tabela">
<p:menuitem value="Gerar Cupom" action="#{relatorioControle.gerarReciboVendaCupom(vendaControle.venda.id)}" ajax="false" icon="ui-icon-print"/>
<p:menuitem value="Gerar Comprovante" ajax="false" action="#{relatorioControle.gerarReciboVenda(vendaControle.venda.id)}"
icon="ui-icon-print"/>
<p:menuitem value="Gerar Receita" ajax="false" rendered="#{loginControler.moduloOtica eq true}" action="#{relatorioControle.gerarReciboVendaReceita(vendaControle.venda.id)}"
icon="ui-icon-print"/>
<p:menuitem value="Compartilhar" onclick="PF('dlgEmail').show()"
icon="ui-icon-mail-closed"/>
<p:menuitem value="Editar" action="#{vendaControle.editar(vendaControle.venda)}" ajax="false"
icon="ui-icon-pencil"/>
<p:menuitem value="Excluir" action="#{vendaControle.validaEstornoVenda(vendaControle.venda)}"
onclick="if (!confirm('Deseja realmente excluir essa venda?'))
return false"
ajax="false"
icon="ui-icon-trash"/>
</p:contextMenu>
Bean
public void carregaListaDeVendas() {
if (tipoBusca == null) {
tipoBusca = "data";
}
if (tipoBusca.equals("nome")) {
if (pessoa.getId() == 0) {
listaDeVendas = null;
} else {
listaDeVendas = vendaFacade.validaVendaDiasPessoa(pessoa);
}
} else if (tipoBusca.equals("data")) {
pessoa = pessoaFacade.listaUm().get(0);
if (somenteConsumidor == Boolean.TRUE) {
listaDeVendas = vendaFacade.validaVendaDiasConsumidor(dataFiltro, dataFiltro2, pessoa);
} else {
listaDeVendas = vendaFacade.validaVendaDias(dataFiltro, dataFiltro2);
}
} else if (tipoBusca.equals("cod")) {
listaDeVendas = vendaFacade.validaVendaCod(id);
} else if (tipoBusca.equals("item")) {
listaDeItensVendas = itemVendaFacade.listaProdutoPorVenda(produto, dataFiltro, dataFiltro2);
}
}
Error
Advertência: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.Facesexception: Datamodel must implement org.primefaces.model.Selectabledatamodel when Selection is enabled. at org.primefaces.Component.datatable.Datatable.getRowKeyFromModel(Datatable.java:1259) at org.primefaces.Component.datatable.Datatablerenderer.encodeRow(Datatablerenderer.java:961) at org.primefaces.Component.datatable.Datatablerenderer.encodeRows(Datatablerenderer.java:907) at org.primefaces.Component.datatable.Datatablerenderer.encodeTbody(Datatablerenderer.java:854) at org.primefaces.Component.datatable.Datatablerenderer.encodeScrollBody(Datatablerenderer.java:408) at org.primefaces.Component.datatable.Datatablerenderer.encodeScrollableTable(Datatablerenderer.java:355) at org.primefaces.Component.datatable.Datatablerenderer.encodeMarkup(Datatablerenderer.java:249) at org.primefaces.Component.datatable.Datatablerenderer.encodeEnd(Datatablerenderer.java:87) at javax.faces.Component.UIComponentBase.encodeEnd(Uicomponentbase.java:920) at org.primefaces.renderkit.CoreRenderer.renderChild(Corerenderer.java:89) at org.primefaces.renderkit.CoreRenderer.renderChildren(Corerenderer.java:72) at org.primefaces.Component.panel.Panelraddressr.encodeContent(Panelraddressr.java:206) at org.primefaces.Component.panel.Panelrenderer.encodeMarkup(Panelrenderer.java:123) at org.primefaces.Component.panel.Panelrenderer.encodeEnd(Panelrenderer.java:58) at javax.faces.Component.UIComponentBase.encodeEnd(Uicomponentbase.java:920) at javax.faces.Component.UIComponent.encodeAll(Uicomponent.java:1863) at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) javax.faces.Component.UIComponentBase.encodeChildren(Uicomponentbase.java:890) at javax.faces.Component.UIComponent.encodeAll(Uicomponent.java:1856) at javax.faces.Component.UIComponent.encodeAll(Uicomponent.java:1859) at javax.faces.Component.UIComponent.encodeAll(Uicomponent.java:1859) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(Faceletviewhandlingstrategy.java:458) at com.sun.faces.application.view.MultiViewHandler.renderView(Multiviewhandler.java:134) at javax.faces.application.ViewHandlerWrapper.renderView(Viewhandlerwrapper.java:337) with.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:659) at org.apache.Catalina.core.Standardwrapper.service(Standardwrapper.java:1682) at org.apache.Catalina.core.Applicationfilterchain.internalDoFilter(Applicationfilterchain.java:344) at org.apache.Catalina.core.Applicationfilterchain.doFilter(Applicationfilterchain.java:214) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:368) at org.springframework.security.web.access.intercept.Filtersecurityinterceptor.invoke(Filtersecurityinterceptor.java:109) org.springframework.security.web.access.intercept.Filtersecurityinterceptor.doFilter(Filtersecurityinterceptor.java:83) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(Exceptiontranslationfilter.java:97) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.Session.SessionManagementFilter.doFilter(Sessionmanagementfilter.java:100) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.Authentication.AnonymousAuthenticationFilter.doFilter(Anonymousauthenticationfilter.java:78) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(Securitycontextholderawarerequestfilter.java:54) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(Requestcacheawarefilter.java:35) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.Authentication.www.Basicauthenticationfilter.doFilter(Basicauthenticationfilter.java:177) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.Authentication.AbstractAuthenticationProcessingFilter.doFilter(Abstractauthenticationprocessingfilter.java:187) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.Authentication.logout.Logoutfilter.doFilter(Logoutfilter.java:105) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(Securitycontextpersistencefilter.java:79) at org.springframework.security.web.Filterchainproxy$Virtualfilterchain.doFilter(Filterchainproxy.java:380) at org.springframework.security.web.Filterchainproxy.doFilter(Filterchainproxy.java:169) 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:214) at org.apache.Catalina.core.Standardwrappervalve.invoke(Standardwrappervalve.java:316) at org.apache.Catalina.core.Standardcontextvalve.invoke(Standardcontextvalve.java:160) at org.apache.Catalina.core.Standardpipeline.doInvoke(Standardpipeline.java:734) at org.apache.Catalina.core.Standardpipeline.invoke(Standardpipeline.java:673) at com.sun.Enterprise.web.Webpipeline.invoke(Webpipeline.java:99) at org.apache.Catalina.core.Standardhostvalve.invoke(Standardhostvalve.java:174) at org.apache.Catalina.connector.Coyoteadapter.doService(Coyoteadapter.java:416) at org.apache.Catalina.connector.Coyoteadapter.service(Coyoteadapter.java:283) at com.sun.Enterprise.v3.services.impl.Containermapper$Httphandlercallable.call(Containermapper.java:459) at com.sun.Enterprise.v3.services.impl.ContainerMapper.service(Containermapper.java:167) at org.glassfish.Grizzly.http.server.HttpHandler.runService(Httphandler.java:206) at org.glassfish.Grizzly.http.server.HttpHandler.doHandle(Httphandler.java:180) at org.glassfish.Grizzly.http.server.HttpServerFilter.handleRead(Httpserverfilter.java:235) at org.glassfish.Grizzly.filterchain.Executorresolver$9.execute(Executoresolver.java:119) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.executeFilter(Defaultfilterchain.java:284) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.executeChainPart(Defaultfilterchain.java:201) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.execute(Defaultfilterchain.java:133) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.process(Defaultfilterchain.java:112) at org.glassfish.Grizzly.ProcessorExecutor.execute(Processorexecutor.java:77) at org.glassfish.Grizzly.nio.transport.TCPNIOTransport.fireIOEvent(Tcpniotransport.java:526) at org.glassfish.Grizzly.strategies.Abstractiostrategy.fireIOEvent(Abstractiostrategy.java:112) at org.glassfish.Grizzly.strategies.Workerthreadiostrategy.run0(Workerthreadiostrategy.java:117))
Place your implementation and place the full error stack please.
– Filipe L. Constante
Ready Edited the Question
– Leandro Santos
Take a look at this answer and see if you can... https://stackoverflow.com/questions/10526857/facesexception-datamodel-must-implement-org-primefaces-model-selectabledatamode
– Filipe L. Constante