Error au render screen in pimefaces application - Nullpointexception

Asked

Viewed 212 times

3

Uu method, to be called gives NullPointException.

Has an expression that validates when editing appears header "Product Editing", if New registration appears "new". No cadastroProdutoBean.java has method boolean isEditando, on it is giving error.

Method:

public boolean isEditando() {
    return this.produto.getId() != null; 
}

Expression in xhtml:

#{cadastroProdutoBean.editando ? 'Edição de Produto' : 'Novo Produto'}

Follow the log:

 GRAVE: Error Rendering View[/produtos/CadastroProduto.xhtml]
javax.el.ELException: /produtos/CadastroProduto.xhtml: Error reading 'editando' on type com.oliveira.pedidovenda.controller.CadastroProdutoBean
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:88)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
    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)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    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:651)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    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)
Caused by: java.lang.NullPointerException
    at com.oliveira.pedidovenda.controller.CadastroProdutoBean.isEditando(CadastroProdutoBean.java:106)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:99)
    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.AstValue.getValue(AstValue.java:184)
    at org.apache.el.parser.AstChoice.getValue(AstChoice.java:44)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:238)
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
    ... 32 more

01:32:40.663 [http-bio-8080-exec-6] ERROR com.oliveira.pedidovenda.util.jsf.JsfExceptionHandler - Erro de sistema: /produtos/CadastroProduto.xhtml: Error reading 'editando' on type com.oliveira.pedidovenda.controller.CadastroProdutoBean
javax.el.ELException: /produtos/CadastroProduto.xhtml: Error reading 'editando' on type com.oliveira.pedidovenda.controller.CadastroProdutoBean
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:88) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [javax.faces-2.2.8-15.jar:2.2.8-15]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:651) [javax.faces-2.2.8-15.jar:2.2.8-15]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) [catalina.jar:7.0.70]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.70]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat7-websocket.jar:7.0.70]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.70]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.70]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) [catalina.jar:7.0.70]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [catalina.jar:7.0.70]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) [catalina.jar:7.0.70]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) [catalina.jar:7.0.70]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:7.0.70]
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) [catalina.jar:7.0.70]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [catalina.jar:7.0.70]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) [catalina.jar:7.0.70]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082) [tomcat-coyote.jar:7.0.70]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623) [tomcat-coyote.jar:7.0.70]
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) [tomcat-coyote.jar:7.0.70]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_92]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_92]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-coyote.jar:7.0.70]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_92]
Caused by: java.lang.NullPointerException
    at com.oliveira.pedidovenda.controller.CadastroProdutoBean.isEditando(CadastroProdutoBean.java:106) ~[classes/:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_92]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_92]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_92]
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:99) ~[el-api.jar:2.2.FR]
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at org.apache.el.parser.AstValue.getValue(AstValue.java:184) ~[jasper-el.jar:7.0.70]
    at org.apache.el.parser.AstChoice.getValue(AstChoice.java:44) ~[jasper-el.jar:7.0.70]
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) ~[jasper-el.jar:7.0.70]
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) ~[weld-servlet-2.3.2.Final.jar:2.3.2.Final]
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:238) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85) ~[javax.faces-2.2.8-15.jar:2.2.8-15]
    ... 32 more     
  • Hello, Adriano. Welcome to [en.so]! Next time, try to format your question better by correctly putting the code and the log as I did above, otherwise it is very difficult to understand what is happening. Also, try not to use comments to add code or information. You should edit your question and add there.

1 answer

2


The expression in the method isEditando will launch an NPE if the attribute produto is void.

To fix the problem, either you must ensure that the product is selected before the method is executed or check for value in the variable, for example:

return this.produto != null && this.produto.getId() != null; 
  • Thanks for the tip I’m new "stackoverflow" and in forums, I liked the tip was favorable, error is no longer appearing, but is not loading data in the edition, as if I am not passing method, appears selected id but blank fields, expression does not always work new product on screen editing, I will make a few more attempts see what is wrong, if you have any tips I am waiting thank you!!!.

  • @Adriano check the scope of the bean. If it is session or Request. You may be recreating the bean and losing the value of the selected product.

  • Beauty now worked, thanks; I was with Viewscoped: 'import javax.faces.bean.Viewscoped;' switched to Viewscoped: 'import javax.faces.view.Viewscoped;' excellent thank you very much!!!

  • hello utluiz I’m having trouble returning null when savar product has how to help me

  • Hello Utluiz I’m having a problem retn null when saving postei stack take a look. [http://answall.com/questions/149546/retorno-nulo-cadastrar-novo-producto-mas-quando-edito-salvar-n%C3%A3o-dar/149570#149570]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.