0
I select the object through the bean and the link in the data table change in a dialog and when giving the dialog’s Ubmit I get the nullPoiterException error. Someone would know why?
Bean code
@Named
@ViewScoped
public class PesquisaPrevisaoBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private Historicos previsoes;
private List<Historico> listaDePrevisoes;
private Historico previsaoSelecionada;
private CadastroHistoricoService cadastroHistoricoService;
private PrevisaoLazyList lazyPrevisoes;
public List<Historico> getPrevisoes() {
return listaDePrevisoes;
}
public void inicializar() {
// carregarListaHistoricos();
lazyPrevisoes = new PrevisaoLazyList(previsoes);
}
public void carregarListaHistoricos() {
listaDePrevisoes = previsoes.carregaHistorico();
}
public void excluir() {
previsoes.remover(previsaoSelecionada);
this.listaDePrevisoes.remove(previsaoSelecionada);
FacesUtil.addInfoMessage("Provisão " + " excluída com sucesso.");
}
public void alterarPrevisao() {
FacesUtil.addInfoMessage("Provisão " + previsaoSelecionada.getProduto().getDescricao());
System.out.println("Provisão " + previsaoSelecionada.getProduto().getDescricao());
cadastroHistoricoService.salvar(previsaoSelecionada);
}
public Historico getPrevisaoSelecionada() {
return previsaoSelecionada;
}
public void setPrevisaoSelecionada(Historico previsaoSelecionada) {
this.previsaoSelecionada = previsaoSelecionada;
}
public PrevisaoLazyList getLazyModel() {
return lazyPrevisoes;
}
}
Code from the list where I select the object and send to the dialog
<p:dataTable id="historicosTable"
value="#{pesquisaPrevisaoBean.lazyModel}" var="historico"
style="margin-top: 20px" emptyMessage="#{msg.nenhum_tecnico}"
rowKey="historico.codigo" selectionMode="single"
selection="#{pesquisaHistoricosBean.historicoSelecionada}"
paginatorPosition="bottom" rows="5" paginator="true"
paginatorTemplate="{RowsPerPageDropdown} {PreviousPageLink} {CurrentPageReport} {NextPageLink}"
currentPageReportTemplate="(#{msg.pagina} {currentPage} #{msg.de} {totalPages}) - (#{msg.registro} {startRecord} #{msg.a} {endRecord}) - Total ({totalRecords} #{msg.registros})"
styleClass="mystyle" paginatorAlwaysVisible="true"
rowsPerPageTemplate="10, 20, 30" lazy="true">
<f:facet id="header" name="header">
Previsão de Vendas
</f:facet>
<p:column headerText=" Codigo do Produto"
sortBy="#{historico.produto.codigoProduto}"
style="text-align: center; width: 140px">
<p:commandLink value="#{historico.produto.codigoProduto}"
update=":userDetailForm:display" oncomplete="userDialog.show()"
title="View">
<f:setPropertyActionListener value="#{historico}"
target="#{pesquisaPrevisaoBean.previsaoSelecionada}" />
</p:commandLink>
</p:column>
Dialog code
<p:dialog header="User Detail" widgetVar="userDialog"
resizable="false" id="userDlg">
<h:form id="userDetailForm">
<p:panelGrid id="display" columns="2" cellpadding="4"
style="margin:0 auto;">
<h:outputText value="Previsao:"></h:outputText>
<h:inputText
value="#{pesquisaPrevisaoBean.previsaoSelecionada.produto.quantidadeRecente}"
required="true" requiredMessage="Please Enter Name!" />
<f:facet name="footer">
<p:commandButton id="alterar" value="Alterar"
update=":frmPesquisa:historicosTable"
oncomplete="tratarAssociacao(args)"
actionListener="#{pesquisaPrevisaoBean.alterarPrevisao}" />
</f:facet>
</p:panelGrid>
</h:form>
</p:dialog>
Console Output - Error message:
jun 01, 2017 3:34:59 PM javax.faces.event.MethodExpressionActionListener processAction
GRAVE: 'java.lang.NullPointerException' recebido ao invocar escuta de ação '#{pesquisaPrevisaoBean.alterarPrevisao}' para o componente 'alterar'
jun 01, 2017 3:34:59 PM javax.faces.event.MethodExpressionActionListener processAction
GRAVE: java.lang.NullPointerException
at br.com.previsao.controller.PesquisaPrevisaoBean.alterarPrevisao(PesquisaPrevisaoBean.java:71)
at br.com.previsao.controller.PesquisaPrevisaoBean$Proxy$_$$_WeldClientProxy.alterarPrevisao(PesquisaPrevisaoBean$Proxy$_$$_WeldClientProxy.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:775)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251)
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:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
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:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:96)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
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:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
You are initiating the variable
previsaoSelecionada
?– igventurelli
it is loaded through the Listener action inside the commandLink with the value of the list object
– user2509556
When placing an exit to see the variable it shows content.
– user2509556
Which line of null Pointer? Puts the console output
– igventurelli
Provision MEDICAL VIAL VC Jun 01, 2017 3:34:59 PM javax.faces.Event.Methodexpressionactionlistener processAction GRAVE: 'java.lang.Nullpointerexception' received when calling action listening '#{searchPrevisaoBean.alterarPrevisao}' for the 'change' component'
– user2509556
line 71 register Historyservice.save(forecastsSelected);
– user2509556
Put the console output to the question. The entire output. Take advantage and put the entire Managedbean as well.
– igventurelli
ready see if you can help....
– user2509556
Let’s go continue this discussion in chat.
– igventurelli
this giving the save and the component change as you can see, but is loading the value
– user2509556