Page rendering error after system navigation

Asked

Viewed 232 times

0

I have a problem with a developed system which is that as the user browses the system after a certain time the pages do not render but return when the user updates the page. I researched a lot but I could not find a solution and the error that gives does not help much to solve too.

Obs: error does not only give on the page in question "agents".

Obs. 2: the nullpointer error seems to be in a Filter class created, but still do not know what comes null to her


03-Sep-2018 12:27:54.885 SEVERE [http-nio-8084-exec-13] com.sun.faces.application.view.FaceletViewHandlingStrategy.handleRenderException Error Rendering View[/agentes.xhtml]
java.lang.NullPointerException
at com.sun.faces.application.view.ViewScopeContextManager.destroyBeans(ViewScopeContextManager.java:171)
at com.sun.faces.application.view.ViewScopeContextManager.clear(ViewScopeContextManager.java:122)
at com.sun.faces.application.view.ViewScopeManager.removeEldestViewMap(ViewScopeManager.java:399)
at com.sun.faces.application.view.ViewScopeManager.processPostConstructViewMap(ViewScopeManager.java:298)
at com.sun.faces.application.view.ViewScopeManager.processEvent(ViewScopeManager.java:244)
at com.sun.faces.application.view.ViewScopeEventListener.processEvent(ViewScopeEventListener.java:68)
at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2169)
at com.sun.faces.application.ApplicationImpl.invokeListenersFor(ApplicationImpl.java:2142)
at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:294)
at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:739)
at javax.faces.component.UIViewRoot.getViewMap(UIViewRoot.java:1557)
at com.sun.faces.application.view.ViewScopeContextManager.createBean(ViewScopeContextManager.java:148)
at com.sun.faces.application.view.ViewScopeContext.get(ViewScopeContext.java:137)
at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:76)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:761)
at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:107)
at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
at org.jboss.weld.environment.servlet.util.ForwardingELResolver.getValue(ForwardingELResolver.java:49)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:66)
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:80)
at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
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.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.UIData.getValue(UIData.java:732)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:764)
at org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:1015)
at org.primefaces.component.datatable.DataTableRenderer.preRender(DataTableRenderer.java:97)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:85)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
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:889)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at org.primefaces.component.tabview.TabViewRenderer.encodeTabContent(TabViewRenderer.java:313)
at org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:271)
at org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:132)
at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:71)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
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:456)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
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:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.primefaces.Apollo.filter.Characterencodingfilter.doFilter(Characterencodingfilter.java:35)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

Class : Characterencodingfilter

package org.primefaces.apollo.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterEncodingFilter implements Filter {

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {

    req.setCharacterEncoding("UTF-8");
    resp.setCharacterEncoding("UTF-8");
    chain.doFilter(req, resp);          

}



public void init(FilterConfig filterConfig) throws ServletException {

}

public void destroy() {

}

}

4 answers

0


People after weeks researching I managed to find the solution to the problem and I report to you in case there is someone else in need as well. As I use a CDI Viewscoped ( javax.faces.view.Viewscoped ) I should then put the Bean to be managed by CDI, and this was not the case.

Workaround: Configure the following Beans manager in Web.xml (if you haven’t already done so):

<resource-env-ref>
    <resource-env-ref-name>BeanManager</resource-env-ref-name>
    <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>

Put the file context.xml the following content:

<?xml version="1.0" encoding="UTF-8"?>
 <Context>
   <Manager pathname=""/>
  <Resource name="BeanManager" auth="Container" 
     type="javax.enterprise.inject.spi.BeanManager" 
     factory="org.jboss.weld.resources.ManagerObjectFactory"/>
 </Context>

That way the pages started working perfectly.

Provided solution from the following website: http://respostas.guj.com.br/27729-javaxfacesviewviewscoped-nao-funciona-no-mojarra-228-

0

post the xhtml file of the tbm page, next to the bean corresponding to msm

0

Follow the remaining codes

Agent.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:p="http://primefaces.org/ui"
            xmlns:pe="http://primefaces.org/ui/extensions"
            template="/WEB-INF/template.xhtml">

<f:metadata>
    <f:viewParam name="dummy"/>
</f:metadata>


<ui:define name="content">
    <title>Cadastro de Agentes Funerários</title>

    <div class="ui-g">
        <div class="ui-g-12 ui-md-12 ui-lg-12">
            <div class="card">
                <h1><i class="fa fa-users  Fs30 Blue"></i> <p:spacer width="10"/><span class="Fs22 Red">Agente:</span> <span class="Fs16">Cadastramento de informações de agentes.</span></h1>    
                <h:form id="frm">
                    <p:messages id="messages" autoUpdate="true" closable="true" />                         
                </h:form>
            </div>
        </div>



        <div class="ui-g-12 ui-md-12 ui-lg-12">
            <div class="card">
                <p:tabView id="tab" widgetVar="wg_tab">                           
                    <p:tab title="Consulta">
                        <h:panelGrid columns="0"  style="width: 100%">
                            <h:form id="form_geral">
                                <div class="ui-g-12 ui-md-12 ui-lg-12">
                                    <p:toolbar style="padding: 10px;">
                                        <f:facet name="left">

                                            <p:commandButton  value="Novo"                                                                      
                                                              icon="fa fa-plus Fs14 White"
                                                              actionListener="#{agenteView.incluir}"   
                                                              oncomplete="PF('wg_tab').select(1)"
                                                              update=":tab:form_agente"/>    

                                            <span class="space"/>
                                            <p:commandButton  type="button" value="Imprimir" title="Print" icon="fa fa-print Fs14 White" />

                                        </f:facet>

                                        <f:facet name="right">
                                            <p:commandButton type="button" value="Voltar" title="Voltar" icon="fa fa-history Fs14 White" onclick="history.go(-1)"/>
                                        </f:facet>

                                    </p:toolbar>
                                </div>  
                                <div class="ui-g-12 ui-md-12 ui-lg-12">
                                    <p:dataTable id="tabela_agente" var="age" value="#{agenteView.agentes}" selectionMode="single" rowKey="#{age.id}" selection="#{agenteView.agente}"
                                                 lazy="true" rows="15" paginator="true" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                                 currentPageReportTemplate="{currentPage} de {totalPages}" pageLinks="6" paginatorPosition="bottom"
                                                 rowsPerPageTemplate="5,10,15" emptyMessage="Nenhum Agente encontrado com este critério de seleção" reflow="true">


                                        <p:column headerText="Nome" width="40" sortBy="#{age.nome}">
                                            <h:outputText value="#{age.nome}" />
                                        </p:column>

                                        <p:column headerText="Telefone" width="20">
                                            <h:outputText value="#{age.telefone}" converter="foneConverter" />
                                        </p:column>


                                        <p:column  id="operacoes" width="30" style="text-align: center">                                                          
                                            <f:facet name="header">Ações</f:facet>  
                                            <p:commandLink actionListener="#{agenteView.excluir(age.id)}" update=":growl :tab:form_geral:tabela_agente" title="Excluir um Agente" onsuccess="fechaMessage(3000)" >
                                                <h:graphicImage library="imagens" name="deletar.png" />                                
                                                <p:confirm header="Atenção!!!" message="Deseja realmente excluir o registro?" icon="ui-icon-alert" />                                            
                                            </p:commandLink>
                                            <p:spacer width="5"/>  
                                            <p:commandLink 
                                                title="Alterar um Agente"        
                                                actionListener="#{agenteView.editar(age.id)}"   
                                                oncomplete="handleSaveRequest(xhr,status,args);"
                                                update=":growl :tab:form_agente">

                                                <h:graphicImage library="imagens" name="open.gif" />   
                                                <p:resetInput target=":tab:form_agente" />
                                            </p:commandLink>  
                                        </p:column> 

                                    </p:dataTable>
                                </div>   
                            </h:form>
                        </h:panelGrid>
                    </p:tab>  



                    <p:tab title="Edição" disabled="true">
                        <h:panelGrid columns="0"  style="width: 100%"> 

                            <h:form id="form_agente">
                                <div class="ui-fluid ui-g-11">
                                    <p:focus id="foco" context="form_agente"/> 
                                    <div class="ui-g-12 ui-md-12 ui-lg-12 ">
                                        <div class="Fs22 Red">Dados do Agente</div>
                                        <div class="NoIndent Separator"></div>
                                    </div>


                                    <div class="ui-g-12 ui-md-6 ui-lg-12">
                                        <div class="ui-g-12 ui-md-6 ui-lg-5">
                                            <p:outputLabel value="Nome:" style="font-weight: bold" for="nome" />
                                            <p:inputText id="nome" value="#{agenteView.agente.nome}" maxlength="30" required="true"/>
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-2">
                                            <p:outputLabel value="RG:" style="font-weight: bold" for="rg" />
                                            <p:inputText id="rg" value="#{agenteView.agente.rg}" maxlength="15" />
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-2">
                                            <p:outputLabel value="CPF:" style="font-weight: bold" for="cpf" />
                                            <p:inputText id="cpf" value="#{agenteView.nrCPF}" maxlength="14" required="true">
                                                <p:ajax event="blur" listener="#{agenteView.onBlurCPF()}" update=":growl " process="@this"/>
                                            </p:inputText>                                                    
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-2">
                                            <p:outputLabel value="PIS:" style="font-weight: bold" for="pis" />
                                            <p:inputText id="pis" value="#{agenteView.agente.pis}" maxlength="20" />
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-1">
                                            <p:outputLabel value="Nascimento:" style="font-weight: bold" for="nasc" />
                                            <p:calendar id="nasc" value="#{agenteView.agente.data_nascimento}" pattern="dd/MM/yyyy" mask="true" />
                                        </div>
                                    </div>

                                    <div class="ui-g-12 ui-md-6 ui-lg-12">
                                        <div class="ui-g-12 ui-md-6 ui-lg-1">
                                            <p:outputLabel value="CEP:" style="font-weight: bold" for="cep" />
                                            <p:inputMask id="cep" value="#{agenteView.agente.cep}" mask="?99999-999" converter="cepConverter" validator="cepValidator" required="true">
                                                <p:ajax event="blur" listener="#{agenteView.trataEndereco}" update="cid bairro uf ender"/>
                                            </p:inputMask>
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-4">
                                            <p:outputLabel value="Endereço:" style="font-weight: bold" for="ender" />
                                            <p:inputText id="ender" value="#{agenteView.agente.endereco}" maxlength="30" required="true" />
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-3">
                                            <p:outputLabel value="Complemento:" style="font-weight: bold" for="comp" />
                                            <p:inputText id="comp" value="#{agenteView.agente.complemento}"  maxlength="30"/>
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-4">
                                            <p:outputLabel value="Bairro:" style="font-weight: bold" for="bairro" />
                                            <p:inputText id="bairro" value="#{agenteView.agente.bairro}" maxlength="30" required="true"/>
                                        </div>
                                    </div>

                                    <div class="ui-g-12 ui-md-6 ui-lg-12">                                           
                                        <div class="ui-g-12 ui-md-6 ui-lg-2">
                                            <p:outputLabel value="Estado:" style="font-weight: bold" for="uf" />                                                                                   
                                            <p:selectOneMenu id="uf" value="#{agenteView.estado}"  style="display: flex !important;"  autoWidth="false" converter="estadoConverterCDI">
                                                <f:selectItem itemLabel="Selecione" itemValue=""/>
                                                <f:selectItems value="#{agenteView.estados}" var="var" itemLabel="#{var.nome}" itemValue="#{var}"/>                                                    
                                                <p:ajax event="change" listener="#{agenteView.mudouEstado}" update="cid" process="@this"/>
                                            </p:selectOneMenu>
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-2">
                                            <p:outputLabel value="Cidade:" style="font-weight: bold" for="cid" />                                                                                   
                                            <p:selectOneMenu id="cid" value="#{agenteView.agente.cidade}"  style="display: flex !important;"  autoWidth="false" converter="cidadeConverterCDI" > 
                                                <f:selectItem itemLabel="Selecione" itemValue=""/>
                                                <f:selectItems value="#{agenteView.cidades}" var="rem" itemLabel="#{rem.nome}" itemValue="#{rem}"/>
                                            </p:selectOneMenu>
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-2">
                                            <p:outputLabel value="Telefone:" style="font-weight: bold" for="fone" />
                                            <p:inputMask id="fone" value="#{agenteView.agente.telefone}" required="true" mask="(99) 99999999?9" converter="foneConverter" validator="foneValidator"/>                                               
                                        </div>
                                        <div class="ui-g-12 ui-md-6 ui-lg-2">
                                            <p:outputLabel value="Telefone:" style="font-weight: bold" for="fone2" />
                                            <p:inputMask id="fone2" value="#{agenteView.agente.telefone2}" mask="(99) 99999999?9" converter="foneConverter" validator="foneValidator"/>                                               
                                        </div>

                                    </div>                              
                                </div> 

                                <div class="ui-g-11 ui-md-12 ui-lg-12">
                                    <div class="SeparatorFull"></div>

                                    <p:toolbar>                                            
                                        <f:facet name="left">   

                                            <p:commandButton id="btnSalvar" value="Salvar" icon="fa fa-save White"
                                                             actionListener="#{agenteView.salvar()}" update=":growl :tab:form_geral:tabela_agente" 
                                                             oncomplete="handleSaveRequest(xhr,status,args);"  />                                                                                                   

                                            <span class="space"/>

                                            <p:commandButton type="reset" id="btnFechar" value="Voltar" icon="fa fa-history White" onclick="PF('wg_tab').select(0);" /> 
                                        </f:facet>                                             
                                    </p:toolbar> 
                                </div>

                            </h:form>
                        </h:panelGrid> 
                    </p:tab>  

                    <p:tab title="Pesquisar">
                        <h:panelGrid columns="0"  style="width: 100%"> 

                            <h:form id="form_pesquisa">
                                <div class="ui-g-12 ui-md-12 ui-lg-12">
                                    <div class="ui-g-12 ui-md-6 ui-lg-5 ui-fluid">
                                        <p:outputLabel value="Nome do Agente (auto complete):" style="font-weight: bold" for="agenauto" />                                            
                                        <p:autoComplete id="agenauto" forceSelection="true" maxlength="50" size="50" maxResults="8" minQueryLength="3" queryDelay="500"
                                                        value="#{agenteView.filtro.agente}" completeMethod="#{agenteView.completeCliente}"  var="agen" itemLabel="#{agen.nome}" itemValue="#{agen}" 
                                                        converter="#{agenteConverter}"/>   
                                    </div>
                                </div>
                                <div class="ui-g-12 ui-md-12 ui-lg-12">
                                    <div class="ui-g-12 ui-md-6 ui-lg-5 ui-fluid">
                                        <p:outputLabel value="Nome do Agente:" style="font-weight: bold" for="nomeAgen" />
                                        <p:inputText id="nomeAgen" value="#{agenteView.filtro.nome}"  />
                                    </div>
                                </div>


                                <div class="ui-g-12 ui-md-12 ui-lg-12" >
                                    <p:toolbar>
                                        <f:facet name="left">
                                            <p:commandButton id="btn_gravar" value="Pesquisar" tabindex="0" icon="fa fa-search" 
                                                             actionListener="#{agenteView.pesquisar()}"                                                                                                            
                                                             update=":tab:form_geral:tabela_agente :growl"
                                                             oncomplete="PF('wg_tab').select(0)">
                                                <p:resetInput target=":tab:form_agente" />  
                                            </p:commandButton>
                                            <span class="space"/>
                                            <p:commandButton  id="btnLimpar" action="#{agenteView.resetaFiltro()}" update=":tab:form_pesquisa" value="Limpar" />
                                            <span class="space"/>
                                            <p:commandButton type="reset" id="btnVoltar" value="Voltar" icon="fa fa-history White" onclick="PF('wg_tab').select(0);" />  
                                        </f:facet>
                                    </p:toolbar> 
                                </div>                                     
                            </h:form>   

                        </h:panelGrid> 
                    </p:tab>  


                </p:tabView>
            </div>               
        </div>

        <script>
            function handleSaveRequest(xhr, status, args) {

                if (!args.sucesso || args.validationFailed) {
                    fechaMessage(6000);
                    return;
                }
                fechaMessage(50);
                if (args.editando) {
                    PF("wg_tab").select(1);
                } else {
                    PF("wg_tab").select(0);
                }
            }
            function fechaMessage(tempo) {
                setTimeout('$(\'#frm\\\\:messages\').hide()', tempo);
            }
        </script>            
    </div>
</ui:define>

Agenteview

/* 
 * AgenteView.java
 *
 * Criado em Sat Mar 10 14:45:52 BRT 2018
 *
 */

 @Named
 @ViewScoped
 public class AgenteView implements Serializable {

private static final long serialVersionUID = 1L;

@Inject
private PermissaoService permissao;

@Inject
private LoginView login;

@Inject
private AgenteService agenteService;


@Inject
private EnderecoService enderecoService;

@Inject
private CidadeService cidadeService;

@Inject
private EstadoService estadoService;

private String mens;
private String nrCPF;

private boolean editando;

private LazyDataModel<Agente> agentes = null;

private FiltroAgente filtro = new FiltroAgente();

private Agente agente;

private Map<String, String> mapEstados = new TreeMap<>();

private Estado estado;

private List<Estado> estados;
private List<Cidade> cidades;

@PostConstruct
public void init() {
    estados = estadoService.listaEstados();
    agente = new Agente();

    agentes = new LazyDataModel<Agente>() {
        private static final long serialVersionUID = 1L;
        int total;

        @Override
        public List<Agente> load(int first, int pageSize,
                String sortField, SortOrder sortOrder,
                Map<String, Object> filters) {

            filtro.setPrimeiroRegistro(first);
            filtro.setQuantidadeRegistros(pageSize);
            filtro.setAscendente(SortOrder.ASCENDING.equals(sortOrder));
            filtro.setPropriedadeOrdenacao(sortField);
            total = agenteService.quantidadeFiltrados(filtro);
            setRowCount(total);

            return agenteService.filtrados(filtro);
        }

        @Override
        public Object getRowKey(Agente registro) {
            return registro != null ? registro.getId() : null;
        }

        @SuppressWarnings("unchecked")
        @Override
        public Agente getRowData(String id) {
            Integer chave = Integer.valueOf(id);

            List<Agente> lista = (List<Agente>) getWrappedData();
            for (Agente agente : lista) {
                if (chave.equals(agente.getId())) {
                    return agente;
                }
            }
            return null;
        }
    };

}

/**
 * Método responsável de passar um registro do tipo Agente para seja
 * excluido do banco de dados
 *
 * @param codigo id da Agente
 */
public void excluir(Integer codigo) {
    if (permissao.temPermissao(login.pegaUser().getPermissoes(), Constantes.AGENTE_EXCLUIR)) {
        mens = agenteService.deletarAgente(codigo);
        if (mens.equals("ok")) {
            FacesUtil.addInfoMessage("Beleza", "Deletado ok");
            FacesUtil.callBackSucesso(true);
        } else {
            FacesUtil.addErrorMessage("Aviso", mens);
            FacesUtil.callBackSucesso(false);
        }
    } else {
        FacesUtil.addFatalMessage("Acesso Negado!!", "Você não tem permissão para executar essa ação");
        FacesUtil.callBackSucesso(false);
    }
}

/**
 * Método responsável de passar um registro do tipo Agente para seja salvo
 * no banco de dados.
 */
public void salvar() {

    if (permissao.temPermissao(login.pegaUser().getPermissoes(), Constantes.AGENTE_ALTERAR)) {

        mens = agenteService.salvarAgente(agente);

        if (mens.equals("ok")) {
            FacesUtil.addInfoMessage("Beleza", "Salvo no banco.");
            FacesUtil.callBackSucesso(true);
        } else {
            FacesUtil.addErrorMessage("Aviso", mens);
            FacesUtil.callBackSucesso(false);
        }

    } else {
        FacesUtil.addFatalMessage("Acesso Negado!!", "Você não tem permissão para executar essa ação");
        FacesUtil.callBackSucesso(false);
    }
}

/**
 * Método responsável de instanciar um novo registro do tipo Agente.
 */
public void incluir() {
    if (permissao.temPermissao(login.pegaUser().getPermissoes(), Constantes.AGENTE_INCLUIR)) {

        agente = new Agente();
        nrCPF = null;
        cidades = null;
        estado = null;
        setEditando(true);
        FacesUtil.callBackEditando(editando);
    } else {
        FacesUtil.callBackSucesso(false);
        FacesUtil.addFatalMessage("Acesso Negado!!", "Você não tem permissão para executar essa ação");
    }
}

/**
 * Método responsável de solicitar um determinado registro do tipo Agente
 * para alteração.
 *
 * @param codigo id do Agente
 */
public void editar(Integer codigo) {
    agente = agenteService.retornaAgente(codigo);
    nrCPF = agente.getCpf();
    estado = agente.getCidade().getEstado();
    cidades = cidadeService.listaCidades(estado.getId());

    setEditando(true);
    FacesUtil.callBackEditando(editando);
}

/**
 * Método que solicita a verificação de consistencia de um determinado CPF
 */
public void onBlurCPF() {

    if (Uteis.naoNulo(getNrCPF())) {
        if (Uteis.isCPF(getNrCPF())) {
            if (agenteService.verificaCPF(getNrCPF())) {
                FacesUtil.addFatalMessage("CPF JÁ EXTISTE NO SISTEMA!", "ATENÇÃO");
                agente.setCpf(null);
            } else {
                agente.setCpf(getNrCPF());
            }
        } else {
            FacesUtil.addFatalMessage("CPF Inválido!", "ATENÇÃO");
        }

    } else {
        FacesUtil.addFatalMessage("CPF em Branco!", "ATENÇÃO");
        agente.setCpf(null);
    }

}

/**
 * Método que traz uma lista de agentes conforme oque o usuário escreve
 *
 * @return Lista de Agentes
 */
public List<Agente> completeCliente(String query) {
    List<Agente> agen = agenteService.listaPrimeiros(query);
    return agen;
}

/**
 * Método que faz uma solicitação de busca de endereço pelo cep
 */
public void trataEndereco() {
    Endereco ender = enderecoService.retornaEndereco(agente.getCep());
    agente.setBairro(ender.getBairro());
    agente.setEndereco(ender.getEndereco());
    agente.setCidade(cidadeService.retornaCidadePeloEstado(ender.getUf(), ender.getCidade()));
    estado = estadoService.retornaEstadoSigla(ender.getUf());
    if (Uteis.naoNulo(estado)) {
        cidades = cidadeService.listaCidades(estado.getId());
    }
}

/**
 * Método que faz uma solicitação para trazer uma lista de cidades baseado
 * no estado passado
 */
public void mudouEstado() {
    setCidades(cidadeService.listaCidades(getEstado().getId()));
}

/**
 * Método que inicializa o filtro novamente
 */
public void resetaFiltro(){
    filtro = new FiltroAgente();
}

public void voltar() {
    setEditando(false);
    FacesUtil.callBackEditando(editando);
}

public LazyDataModel<Agente> getAgentes() {
    return agentes;
}

public void pesquisar() {
}

public FiltroAgente getFiltro() {
    return filtro;
}

public boolean isEditando() {
    return editando;
}

public void setEditando(boolean editando) {
    this.editando = editando;
}

public Agente getAgente() {
    return agente;
}

public void setAgente(Agente agente) {
    this.agente = agente;
}

public String getNrCPF() {
    return nrCPF;
}

public void setNrCPF(String nrCPF) {
    this.nrCPF = nrCPF;
}

public Map<String, String> getMapEstados() {
    return mapEstados;
}

public void setMapEstados(Map<String, String> mapEstados) {
    this.mapEstados = mapEstados;
}

public Estado getEstado() {
    return estado;
}

public void setEstado(Estado estado) {
    this.estado = estado;
}

public List<Estado> getEstados() {
    return estados;
}

public void setEstados(List<Estado> estados) {
    this.estados = estados;
}

public List<Cidade> getCidades() {
    return cidades;
}

public void setCidades(List<Cidade> cidades) {
    this.cidades = cidades;
}

}

0

looking here you are trying to use an object or attribute that this null triggers the other errors, inside your datatable in all components put the rendered attribute = "#{age != null}" and see if the error persists

  • I did a test with what you suggested, however still continues with the problem =/

Browser other questions tagged

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