Tenho um dataTable, e quando seleciono o objeto que eu quero, consigo recuperar aquele objeto selecionado, mais quando tento atualizar. Apresenta uma Exceção
Pagina do dataTable
<ui:composition template="/WEB-INF/template/layoutPadrao.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui">
<ui:define name="titulo">Pesquisa de Fabricantes</ui:define>
<ui:define name="corpo">
<f:metadata>
<f:viewAction action="#{consultaFabricante.inicializa}" />
</f:metadata>
<h1>Pesquisa de Fabricantes</h1>
<h:form id="frmPesquisa">
<p:messages id="messages" autoUpdate="true" closable="true" />
<p:toolbar style="margin-top: 20px">
<p:toolbarGroup>
<p:button value="Novo" outcome="cadastroFabricante" />
</p:toolbarGroup>
</p:toolbar>
<p:dataTable id="fabricantesTable" value="#{consultaFabricante.fabricantes}" var="fabricante"
style="margin-top: 20px" emptyMessage="Nenhum fabricante encontrado." rows="20"
paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom">
<p:column headerText="Código" style="text-align: center; width: 100px">
<h:outputText value="#{fabricante.codigo}" />
</p:column>
<p:column headerText="Nome">
<h:outputText value="#{fabricante.nome}" />
</p:column>
<p:column style="width: 100px; text-align: center" headerText="Editar / Excluir">
<p:button outcome="cadastroFabricante" icon="ui-icon-pencil" title="Editar">
<f:param name="fabricante" value="#{fabricante.codigo}" />
</p:button>
<p:commandButton icon="ui-icon-trash" title="Excluir" oncomplete="PF('confirmacaoExclusao').show()"
process="@this" update=":frmPesquisa:confirmacaoExclusaoDialog">
<f:setPropertyActionListener value="#{fabricante}" target="#{consultaFabricante.fabricanteSelecionado}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog header="Exclusão de fabricante" id="confirmacaoExclusaoDialog"
widgetVar="confirmacaoExclusao" message="Tem certeza que deseja excluir o fabricante "
severity="alert">
<p:button value="Não" onclick="PF('confirmacaoExclusao').hide(); return false;" />
<p:commandButton value="Sim" update=":frmPesquisa:fabricantesTable" oncomplete="PF('confirmacaoExclusao').hide()"
action="#{consultaFabricante.excluir}" />
</p:confirmDialog>
</h:form>
</ui:define>
</ui:composition>
Pagina para atualização
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/WEB-INF/template/layoutPadrao.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui">
<ui:define name="titulo">#{cadastroFabricanteBean.editando ? 'Edição de Fabricante' : 'Novo Fabricante'}</ui:define>
<ui:define name="corpo">
<f:metadata>
<f:viewParam name="fabricante" value="#{cadastroFabricanteBean.fabricante}" />
<f:event listener="#{cadastroFabricanteBean.inicializar}" type="preRenderView" />
</f:metadata>
<h1>#{cadastroFabricanteBean.editando ? 'Edição de Fabricante' : 'Novo Fabricante'}</h1>
<h:form id="frmCadastro">
<p:messages id="messages" autoUpdate="true" closable="true" />
<p:toolbar style="margin-top: 20px">
<p:toolbarGroup>
<p:commandButton value="Salvar" action="#{cadastroFabricanteBean.salvar}" id="botaoSalvar" update="frmCadastro" />
</p:toolbarGroup>
<p:toolbarGroup align="right">
<p:button value="Pesquisa" outcome="pesquisaFabricante" />
</p:toolbarGroup>
</p:toolbar>
<p:panelGrid columns="2" id="painel" style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo">
<p:outputLabel value="Código" for="codigo" />
<p:inputText id="codigo" value="#{cadastroFabricanteBean.fabricante.codigo}" size="20" maxlength="20" readonly="true" />
<p:outputLabel value="nome" for="nome" />
<p:inputText id="nome" value="#{cadastroFabricanteBean.fabricante.nome}" size="60" maxlength="20" />
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
meu converter
package com.irmaosuspension.controleservico.converter;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import com.irmaosuspension.controleservico.cdi.CDIServiceLocator;
import com.irmaosuspension.controleservico.dao.FabricanteDAO;
import com.irmaosuspension.controleservico.modelo.Fabricante;
@FacesConverter(forClass=Fabricante.class)
public class FabricanteConverter implements Converter{
private FabricanteDAO dao;
public FabricanteConverter() {
dao = CDIServiceLocator.getBean(FabricanteDAO.class);
}
public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
Fabricante fabricante = null;
if(value != null){
Long code = new Long(value);
fabricante = dao.buscarPeloCodigo(code);
}
return fabricante;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
if(value != null){
Long code = ((Fabricante)value).getCodigo();
return code == null ? null : value.toString();
}
return "";
}
}
Meu Erro:
mar 10, 2017 2:27:37 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
ADVERTÊNCIA: For input string: "Fabricante(codigo=1, nome=Volkswagem)"
java.lang.NumberFormatException: For input string: "Fabricante(codigo=1, nome=Volkswagem)"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.<init>(Long.java:965)
at com.irmaosuspension.controleservico.converter.FabricanteConverter.getAsObject(FabricanteConverter.java:25)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:171)
at javax.faces.component.UIViewParameter.getConvertedValue(UIViewParameter.java:437)
at javax.faces.component.UIInput.validate(UIInput.java:975)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIViewParameter.processValidators(UIViewParameter.java:278)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)