I have two classes that there is a relationship # OneToMany (Pay and Split) the code below:
#Entity
#Table(name="pagamento")
public class Pagamento implements Serializable { //Class Pay
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="idpagamento")
private int id;
...
#ManyToOne()
#JoinColumn(name="idconta")
private Divida coddivida;
and below class Split
#Entity
#Table(name="divida")
public class Divida implements Serializable{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "idconta")
private int id;
...
#OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="coddivida", targetEntity = Pagamento.class)
private List<Pagamento> pagamento;
And I search through the data code below:
public List<Divida> getDividas(){
return getCleanListOfObjects(Divida.class,"from Divida divida");
}
And I'm trying to display in a datatable is as below:
<p:dataTable id="paneluser" value="#{dividaFaces.listofDivida}" var="divida" selection="#{dividaFaces.selectedDivida}"
rowKey="#{divida.id}" selectionMode="sigle" emptyMessage="Não existe Dívida" paginator="true" rows="10">
<f:facet name="header">
Panel de Dívidas Cadastradas
</f:facet>
<p:column headerText="Descricão">
#{divida.descricao}
</p:column>
<p:column id="pagar" headerText="Tela de Pagamento">
<p:commandButton value="Pagar">
<p:ajax oncomplete="pagetela.show()" update="telapgamento"/>
</p:commandButton>
</p:column>
<f:facet name="footer">
Financé v#{sistema.VERSION}
</f:facet>
</p:dataTable>
But it is giving the error below:
Hibernate:
/*
from
Divida divida */ select
divida0_.idconta as idconta0_,
divida0_.datadeinicio as datadein2_0_,
divida0_.descricaodespesa as descrica3_0_,
divida0_.empresa as empresa0_,
divida0_.exercicio as exercicio0_,
divida0_.observacao as observacao0_,
divida0_.operacaobancaria as operacao7_0_,
divida0_.parcela as parcela0_,
divida0_.tipolancamento as tipolanc9_0_,
divida0_.vencimento as vencimento0_
from
divida divida0_
Lista de Dividas: []
Hibernate:
/*
from
Divida divida */ select
divida0_.idconta as idconta0_,
divida0_.datadeinicio as datadein2_0_,
divida0_.descricaodespesa as descrica3_0_,
divida0_.empresa as empresa0_,
divida0_.exercicio as exercicio0_,
divida0_.observacao as observacao0_,
divida0_.operacaobancaria as operacao7_0_,
divida0_.parcela as parcela0_,
divida0_.tipolancamento as tipolanc9_0_,
divida0_.vencimento as vencimento0_
from
divida divida0_
Mar 26, 2013 8:34:31 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/menu/principal.xhtml]
java.lang.ClassCastException: br.com.finance.model.Divida cannot be cast to java.util.List
at org.primefaces.component.datatable.DataTable.findSelectedRowKeys(DataTable.java:977)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:624)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:234)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:196)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:881)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:851)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
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:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Can anyone help me?
You are using selectionMode="sigle". Please notice the missing 'n' in single. The exception you are encoutering here has nothing to do with Hibernate.
Related
I have a dataTable in JSF to show the phone numbers from a selected user.
Like the image below
My DataTable
In this dataTable I have a column with a commandLink to delete the element. The commandLink is working fine except in one particular case : If I delete the element of the last row and I try to delete any other element my #PostConstruct method is called again and it throws an exception. I concluded that the exception is being called because the param that contains the id of the user is null.
My question is why is this bug triggered only when I delete the last row of the dataTable ?
nov 28, 2022 11:36:54 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/telefone.xhtml]
com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean telefoneBean
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:93)
at org.apache.el.parser.AstValue.getValue(AstValue.java:136)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
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:57)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:417)
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:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.sun.faces.spi.InjectionProviderException
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:115)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
... 65 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
... 67 more
Caused by: java.lang.NumberFormatException: null
at java.base/java.lang.Long.parseLong(Long.java:655)
at java.base/java.lang.Long.parseLong(Long.java:817)
at managedBean.TelefoneManagedBean.init(TelefoneManagedBean.java:42)
... 72 more
nov 28, 2022 11:36:54 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/pos-java-maven-hibernate] threw exception
java.lang.IllegalStateException: CDATA tags may not nest
at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:681)
at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:179)
at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:341)
at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:116)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:124)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
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:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:829)
#PostConstruct
public void init() {
String codUser = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
.get("codigouser");
daoUsuario = new DaoUsuario();
daoTelefone = new DaoTelefone();
telefone = new TelefoneUser();
usuario = daoUsuario.pesquisar(Long.parseLong(codUser), UsuarioPessoa.class);
lista = daoTelefone.consultarLista(usuario);
}
The code of my xhtml page
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.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.org/ui">
<h:head></h:head>
<h:body>
<h:form>
<p:breadCrumb>
<p:menuitem></p:menuitem>
<p:menuitem value="Pagina Index" action="index.jsf" />
<p:menuitem value="Pagina Primefaces" action="primefaces.jsf" />
</p:breadCrumb>
</h:form>
<h:form id="formulario">
<h:messages showDetail="true" showSummary="false" id="msg"></h:messages>
<h:panelGrid columns="2">
<h:outputLabel value="Usuário: " />
<h:outputText value="#{telefoneBean.usuario.nome}" />
<h:outputLabel value="ID " />
<h:inputText value="#{telefoneBean.telefone.id}" readonly="true" />
<h:outputLabel value="Numero: " />
<h:inputText value="#{telefoneBean.telefone.numero}" required="true" />
<h:outputLabel value="Tipo: " />
<h:inputText value="#{telefoneBean.telefone.tipo}" required="true" />
<h:commandButton value="Salvar" action="#{telefoneBean.salvar}" />
</h:panelGrid>
</h:form>
<h:form id="formularioTelefones">
<p:dataTable rowStatePreserved="true" value="#{telefoneBean.lista}"
id="tabelatelefones" var="tel">
<f:facet name="header">Lista de Telefones</f:facet>
<p:column>
<h:outputText value="#{tel.id}" />
<f:facet name="header">ID</f:facet>
</p:column>
<p:column>
<h:outputText value="#{tel.numero}" />
<f:facet name="header">Numero</f:facet>
</p:column>
<p:column>
<f:facet name="header">Tipo</f:facet>
<h:outputText value="#{tel.tipo}" />
</p:column>
<p:column>
<f:facet name="header">Deletar</f:facet>
<h:commandLink id="botaodeletar" action="#{telefoneBean.remover}">
<h:graphicImage url="resources/img/deletar.png" />
<f:setPropertyActionListener value="#{tel}"
target="#{telefoneBean.telefone}" />
<f:ajax execute="botaodeletar" render="#form :formulario:msg" />
</h:commandLink>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
I will explain the bug using this example, lets imagine I delete the row with id= 484.If I do this, I can delete any other row perfectly fine.
Now, lets say I delete the row 503. This row is going to be removed, but if I try to remove any other row my #PostConstruct method is going to be called again and it will throw an exception because the param "codigouser"(this is the param that gets the ID of the user I want) will be null, BUT I still am able to add another number to the list and if I do this the table starts working again (with the same conditions)...
.See the example of a dataTable
First I thought the problem was on the method that I use to delete the phone number in the DB. Then I thought the problem was on the method that I use to get the list of phone numbers in the DB. Then I noticed that this bug just happens when I refresh the values of the dataTable. If I dont refresh the values on the dataTable then everything works perfectly fine, but the problem of course is that the phone numbers I remove still show in the table because I didnt refreshed it.
Edit :
The managed bean class
package managedBean;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import dao.DaoTelefone;
import dao.DaoUsuario;
import model.TelefoneUser;
import model.UsuarioPessoa;
#ManagedBean(name = "telefoneBean")
#ViewScoped
public class TelefoneManagedBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private UsuarioPessoa usuario; // the user
private DaoUsuario daoUsuario; // dao to find the user in the database
private DaoTelefone daoTelefone; // dao to find the phone numbers in the data base
private TelefoneUser telefone; // Object used to save and delete the phone number
private List<TelefoneUser> lista; // list of phone numbers from the user
#PostConstruct
public void init() {
String codUser = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
.get("codigouser"); // getting the user id
daoUsuario = new DaoUsuario();
daoTelefone = new DaoTelefone();
telefone = new TelefoneUser();
usuario = daoUsuario.pesquisar(Long.parseLong(codUser), UsuarioPessoa.class); // getting the user
lista = daoTelefone.consultarLista(usuario); // getting the list of phone numbers
}
public void setUsuario(UsuarioPessoa usuario) {
this.usuario = usuario;
}
public UsuarioPessoa getUsuario() {
return usuario;
}
public TelefoneUser getTelefone() {
System.out.println("telefone");
return telefone;
}
public String remover() throws Exception {
daoTelefone.deleteId(telefone);
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Informação:", "Telefone removido."));
telefone = new TelefoneUser();
return "";
}
public String salvar() {
telefone.setPessoa(usuario);
daoTelefone.salvar(telefone);
telefone = new TelefoneUser();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Informação:", "Telefone Salvo."));
return "";
}
public void setTelefone(TelefoneUser telefone) {
this.telefone = telefone;
}
public DaoUsuario getDaoUsuario() {
return daoUsuario;
}
public void setDaoUsuario(DaoUsuario daoUsuario) {
this.daoUsuario = daoUsuario;
}
public DaoTelefone getDaoTelefone() {
return daoTelefone;
}
public void setDaoTelefone(DaoTelefone daoTelefone) {
this.daoTelefone = daoTelefone;
}
public List<TelefoneUser> getLista() {
lista = daoTelefone.consultarLista(usuario);
return lista;
}
public void setLista(List<TelefoneUser> lista) {
this.lista = lista;
}
}
The method used to remove the phone number :
public void deleteId(E entidade) throws Exception {
Object primaryKey = HibernateUtil.getPrimaryKey(entidade);
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
entityManager.createNativeQuery("delete from "+entidade.getClass().getSimpleName().toLowerCase()+" where id="+primaryKey).executeUpdate();
transaction.commit();
}
In the comment section We found the problem. That was a rendering problem here:
<f:ajax execute="botaodeletar" render="#form :formulario:msg" />
Changed to this:
<f:ajax execute="#this" render=":formulario:msg :formularioTelefones:tabelatelefones" />
I have problems with the selection checkbox in datatable, I add a ajax with "rowSelectCheckbox" event and to select a checkbox suge the following error:
WARNING: Method not found:
tes.sales.bean.DocumentosBean#1821df11.onTestEvent(org.primefaces.event.SelectEvent)
javax.el.MethodNotFoundException: Method not found:
tes.sales.bean.DocumentosBean#1821df11.onTestEvent(org.primefaces.event.SelectEvent)
at
org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271) at
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at
org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processCustomListener(AjaxBehaviorListenerImpl.java:87)
at
org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processArgListener(AjaxBehaviorListenerImpl.java:72)
at
org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:56)
at
org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
at
javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:804)
at javax.faces.component.UIData.broadcast(UIData.java:1086) at
javax.faces.component.UIData.broadcast(UIData.java:1108) at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
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:646) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
jul 06, 2015 5:05:21 PM com.sun.faces.context.AjaxExceptionHandlerImpl
handlePartialResponseError SEVERE: javax.el.MethodNotFoundException:
Method not found:
tes.sales.bean.DocumentosBean#1821df11.onTestEvent(org.primefaces.event.SelectEvent)
at
org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271) at
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at
org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processCustomListener(AjaxBehaviorListenerImpl.java:87)
at
org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processArgListener(AjaxBehaviorListenerImpl.java:72)
at
org.primefaces.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:56)
at
org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
at
javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:804)
at javax.faces.component.UIData.broadcast(UIData.java:1086) at
javax.faces.component.UIData.broadcast(UIData.java:1108) at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
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:646) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
xhtml
<h:form>
<p:dataTable id="myTable" var="mydoc" value="#{DocumentosBean.documentos}" rows="20" paginator="true" sortOrder="descending"
selection="#{DocumentosBean.selectedDocs}" filteredValue="#{DocumentosBean.myFilter}"
sortBy="#{mydoc.id}" rowKey="#{mydoc.id}" rowIndexVar="indexRow">
<p:ajax event="rowSelectCheckbox" listener="#{DocumentosBean.onTestEvent}" />
<p:ajax event="rowUnselectCheckbox" process="#this"/>
<p:ajax event="toggleSelect" process="#this"/>
<p:column selectionMode="multiple" style="min-width:20px;text-align:center;"></p:column>
<p:column headerText="Id">
<h:outputText value="#{mydoc.id}" />
</p:column>
<p:column headerText="Vendedor">
<h:outputText value="#{mydoc.vendedor}" />
</p:column>
<p:column headerText="Moneda">
<h:outputText value="#{mydoc.moneda}" />
</p:column>
<p:column headerText="Operación">
<h:outputText value="#{mydoc.operacion}" />
</p:column>
<p:column headerText="Fecha Creación">
<h:outputText value="#{mydoc.fechaCreacion}" />
</p:column>
<p:column headerText="Estado">
<h:outputText value="#{mydoc.estado}" />
</p:column>
</p:dataTable>
</h:form>
Bean
#ManagedBean(name="DocumentosBean")
#SessionScoped
public class DocumentosBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<ListaDocumentos> documentos;
private ListaDocumentos selectedDoc;
private ListaDocumentos[] selectedDocs;
private List<ListaDocumentos> myFilter;
public DocumentosBean() {
System.out.println("SelectEvent");
documentos = new ArrayList<ListaDocumentos>();
fillData(documentos);
/*myFilter = new ArrayList<ListaDocumentos>();
fillData(myFilter);*/
}
public void onTestEvent(SelectEvent e){
System.out.println(".......");
System.out.println(e.getObject().toString());
}
}
I am trying to Ajax event with p:selectOneRadio> and I'm getting
WARNING: Method not found: com.ccc.managedController.TweetDistributionManagedBean#78159a62.renderUploadPanel(javax.faces.event.AjaxBehaviorEvent)
javax.el.MethodNotFoundException: Method not found: com.ccc.managedController.TweetDistributionManagedBean#78159a62.renderUploadPanel(javax.faces.event.AjaxBehaviorEvent)
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processCustomListener(AjaxBehaviorListenerImpl.java:87)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processArgListener(AjaxBehaviorListenerImpl.java:72)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:56)
at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:106)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Here are more code
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="selectone" value="Upload :" />
<p:selectOneRadio id="selectone"
value="#{tweetDistributionManagedBean.tweetType}">
<f:selectItem itemLabel="Group Tweets" itemValue="GT" />
<f:selectItem itemLabel="Event Tweets" itemValue="ET" />
<f:selectItem itemLabel="Suprachar Tweets" itemValue="ST" />
<p:ajax event="click"
listener="#{tweetDistributionManagedBean.renderUploadPanel}"
update="gtid" process="#form" global="false" />
</p:selectOneRadio>
</h:panelGrid>
and Java bean method
public void renderUploadPanel(final SelectEvent event) {
String selecteValues = (String) event.getObject();
visibleGTFlag = true;
}
Moist likely the 'SelectEvent' is not an event that extends AjaxBehaviourEvent . This can happen if you import the wrong class type. Try this
public void renderUploadPanel(AjaxBehaviorEvent event) {
System.out.println(tweetType);
visibleGTFlag = true;
}
You can try to use the event "ValueChangeEvent", look my example:
public void renderUploadPanel(ValueChangeEvent event) {
String selecteValues = event.getNewValue().toString();
visibleGTFlag = true;
}
can someone help me figure out the problem i'm new on JSF. whenever i load my page and submit my form i get this error :
here is my code :
#ManagedBean
#ApplicationScoped
public class CommandeController extends JSFActions {
final static Logger LOGGER = LoggerFactory.getLogger( CommandeController.class );
#ManagedProperty( value = "#{commandeBean}")
private CommandeBean commandeBean;
#ManagedProperty( value = "#{clientBean}")
private ClientBean clientBean;
#ManagedProperty( value = "#{etablissementBean}")
private EtablissementBean etablissementBean;
#ManagedProperty( value = "#{commandeFacade}")
private ICommandeFacade commandeFacade;
and my xhtml file look like
<h:outputText value="#{lbl.postRef}" />
<p:selectOneMenu value="#{commandeBean.idPoste}">
<f:selectItem itemLabel="Choisissez le poste" itemValue="-1"/>
<f:selectItems value="#{jFActions.postes.entrySet()}" var="post"
itemValue="#{post.key}" itemLabel="#{post.value}"/>
</p:selectOneMenu>
<h:outputText value="#{lbl.langUse}" />
<p:selectOneMenu value="#{commandeBean.langUtilise}">
<f:selectItem itemLabel="Choisissez la langue" itemValue="-1"/>
<f:selectItem itemValue="ar" itemLabel="Arabe"/>
<f:selectItem itemValue="en" itemLabel="Enlish"/>
<f:selectItem itemValue="fr" itemLabel="Frensh"/>
</p:selectOneMenu>
<h:outputText value="#{lbl.nbJ}" />
<p:inputText id="txtNbrJour" value="#{commandeBean.nbJour}" converterMessage="#{msg.nbrInvalid}" >
<f:convertNumber type="number" integerOnly="true" />
</p:inputText>
<h:outputText value="#{lbl.nbjMax}" />
<p:inputText id="txtNJAut" value="#{etablissementBean.nbJourAutorise}" readonly="true" />
ATTENTION: Erreur inattendue lors du traitement du bean géré «commandeController»
com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement du bean géré «commandeController»
at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:398)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:262)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
at org.apache.el.parser.AstValue.getTarget(AstValue.java:94)
at org.apache.el.parser.AstValue.invoke(AstValue.java:259)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
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:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement de la propriété gérée «commandeBean»
at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:117)
at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:353)
... 35 more
Caused by: java.lang.IllegalArgumentException: can't parse argument number commandeBean
at java.text.MessageFormat.makeFormat(MessageFormat.java:1339)
at java.text.MessageFormat.applyPattern(MessageFormat.java:458)
at java.text.MessageFormat.<init>(MessageFormat.java:350)
at java.text.MessageFormat.format(MessageFormat.java:811)
at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:398)
at com.sun.faces.mgbean.BeanBuilder$Expression.validateLifespan(BeanBuilder.java:574)
at com.sun.faces.mgbean.BeanBuilder$Expression.<init>(BeanBuilder.java:523)
at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:363)
at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
... 36 more
18 févr. 2014 10:48:37 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/sgrp-web] threw exception [Erreur inattendue lors du traitement du bean géré «commandeController»] with root cause
java.lang.IllegalArgumentException: can't parse argument number commandeBean
at java.text.MessageFormat.makeFormat(MessageFormat.java:1339)
at java.text.MessageFormat.applyPattern(MessageFormat.java:458)
at java.text.MessageFormat.<init>(MessageFormat.java:350)
at java.text.MessageFormat.format(MessageFormat.java:811)
at com.sun.faces.util.MessageUtils.getExceptionMessageString(MessageUtils.java:398)
at com.sun.faces.mgbean.BeanBuilder$Expression.validateLifespan(BeanBuilder.java:574)
at com.sun.faces.mgbean.BeanBuilder$Expression.<init>(BeanBuilder.java:523)
at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:363)
at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107)
at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:353)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:262)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
at org.apache.el.parser.AstValue.getTarget(AstValue.java:94)
at org.apache.el.parser.AstValue.invoke(AstValue.java:259)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at
any help ??
You are using a NumberConverter to convert an object. Use a custom converter instead.
In my case it was happening because I was logging the JSON {"":{}} output and that why system generating this exception. JSON was treating like a string in LogDebug method.
Use vlogDebug("my log {0}",jsonObject). It will work as it is now in argument {0}.
I'm having trouble with a DataTable.
I have a SelectOneMenu component with 3 options. Every option should render a DataTable with different information.
My xhtml page is working (I tested it with a simple code), but it seems that my backing bean is not working as I was expecting. When I run the page throws an error message.
My xhtml looks like
<h:form>
<h:outputLabel for="reporte" value="Tipo de reporte: " />
<h:selectOneMenu id="reporte"
value="#{reportController.type}">
<f:selectItem itemLabel="Seleccione tipo de reporte..." itemValue="null" />
<f:selectItems value="#{reportController.reportType}" />
<f:ajax execute="#form" render="#form" />
</h:selectOneMenu>
<h:panelGrid id="porSistema"
rendered="#{reportController.type == 'Por sistema'}">
<h:dataTable value="#{reportController.list}" var="item"
border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Nombre del archivo"/>
</f:facet>
<h:outputText value="#{item.fileName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Registros correctos"/>
</f:facet>
<h:outputText value="#{item.registersOk}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Registros incorrectos"/>
</f:facet>
<h:outputText value="#{item.registersNok}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Registros procesados"/>
</f:facet>
<h:outputText value="#{item.registers}"/>
</h:column>
</h:dataTable>
</h:panelGrid>
</h:form>
The bean is
#ManagedBean
#ViewScoped
public class ReportController {
List<Object> list = new ArrayList<Object>();
String type;
String[] reportType = new String[]{"Por sistema",
"Por programa y componente",
"Por estatus de pago"};
#PostConstruct
public void init() {
if (type.equals("Por sistema")) {
list.add(new ReporteSistema("A", "B", "C", "D"));
} else if (type.equals("Por programa y componente")) {
list.add(new ReporteProgramaComponenteA("E", "F", "G", "H", "I", "J"));
} else if (type.equals("Por estatus de pago")) {
list.add(new ReporteProgramaComponenteB("K", "L", "M", "N"));
}
}
public String[] getReportType() {
return reportType;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<Object> getList() {
return list;
}
public void setList(List<Object> list) {
this.list = list;
}
}
and the stack trace is
com.sun.faces.mgbean.ManagedBeanCreationException: Se ha producido un error al realizar la inyección de recurso en el bean administrado reportController
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getCurrentSelectedValues(MenuRenderer.java:648)
at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:749)
at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:844)
at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:298)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at mx.gob.sagarpa.NoCacheFilter.doFilter(NoCacheFilter.java:29)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:349)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: com.sun.faces.spi.InjectionProviderException
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:119)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:99)
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
... 56 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor85.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:117)
... 58 more
Caused by: java.lang.NullPointerException
at mx.gob.sagarpa.beans.ReportController.init(ReportController.java:32)
... 62 more
You seem to be misunderstanding the purpose of the #PostConstruct. This annotation is to be used to specify methods which are to be executed directly after bean's construction. This annotation allows you to execute code after injection of managed properties specified by #ManagedProperty and all other dependencies such as #Inject or #EJB. Those injected properties and dependencies are namely not available inside the bean's constructor (a fully constructed instance of the bean has to be obtained first before all injections can take place, of course). The #PostConstruct of a view scoped bean is not invoked when you send an ajax request on it. It's only invoked when you initially open the page in the browser.
You actually want to invoke that method when the ajax event is fired. You need to change the view and bean as follows in order to get it to work.
<h:selectOneMenu id="reporte" value="#{reportController.type}">
<f:selectItem itemLabel="Seleccione tipo de reporte..." itemValue="null" />
<f:selectItems value="#{reportController.reportType}" />
<f:ajax execute="#form" listener="#{reportController.changeType}" render="#form" />
</h:selectOneMenu>
(note the new listener attribute)
and
public void changeType() { // No, do not put #PostConstruct on it!
if ("Por sistema".equals(type)) {
list.add(new ReporteSistema("A", "B", "C", "D"));
} else if ("Por programa y componente".equals(type)) {
list.add(new ReporteProgramaComponenteA("E", "F", "G", "H", "I", "J"));
} else if ("Por estatus de pago".equals(type)) {
list.add(new ReporteProgramaComponenteB("K", "L", "M", "N"));
}
}
Also note that I swapped the both sides of the equals() so that you can guarantee that it will never throw NPE. If the type happen to be null, then it will simply be compared as non-equal. When you actually invoked equals() on something which is null, you will guaranteed get a NPE (that's what the whole exception stands for! see also its javadoc).
Your problem is obviously stated in the stacktrace. Your init method threw a NullPointerException. To be precise, your type variable was not given any value. You cannot call equals function with it.