NullPointerException when displaying entire list in DataTable with PrimeFaces

0

I need to display all the data in the list in the DataTable using PrimeFaces, but by changing the size of the rowsPerPageTemplate to 300 the data is displayed on the screen, but the filterBy and data editing functions stop working. p>

The following error is displayed on the console:

  

15: 11: 36,096 ERROR   [org.apache.catalina.core.ContainerBase. [jboss.web]. [default-host]. [/ fgtas] [Faces   Servlet] (http-localhost-127.0.0.1-8080-1) Servlet.service () for   servlet Faces Servlet threw exception: java.lang.NullPointerException     at   com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter (PartialViewContextImpl.java:441)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.context.PartialViewContextImpl.access $ 300 (PartialViewContextImpl.java:71)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.context.PartialViewContextImpl $ DelayedInitPartialResponseWriter.getWrapped (PartialViewContextImpl.java:582)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   javax.faces.context.PartialResponseWriter.startDocument (PartialResponseWriter.java:115)   [jboss-jsf-api_2.1_spec-2.0.1.Final.jar: 2.0.1.Final] at   org.primefaces.context.PrimePartialResponseWriter.startDocument (PrimePartialResponseWriter.java:152)   [primefaces-5.1.jar: 5.1] at   com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError (AjaxExceptionHandlerImpl.java:199)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.context.AjaxExceptionHandlerImpl.handle (AjaxExceptionHandlerImpl.java:123)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.lifecycle.Phase.doPhase (Phase.java:119)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.lifecycle.RestoreViewPhase.doPhase (RestoreViewPhase.java:116)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   com.sun.faces.lifecycle.LifecycleImpl.execute (LifecycleImpl.java:118)   [jsf-impl-2.1.7-jbossorg-2.jar:] at   javax.faces.webapp.FacesServlet.service (FacesServlet.java:593)   [jboss-jsf-api_2.1_spec-2.0.1.Final.jar: 2.0.1.Final] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:329)   [jbossweb-7.0.13.Final.jar:] at   org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:248)   [jbossweb-7.0.13.Final.jar:] at   org.primefaces.webapp.filter.FileUploadFilter.doFilter (FileUploadFilter.java:105)   [primefaces-5.1.jar: 5.1] at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:280)   [jbossweb-7.0.13.Final.jar:] at   org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:248)   [jbossweb-7.0.13.Final.jar:] at   org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:275)   [jbossweb-7.0.13.Final.jar:] at   org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:161)   [jbossweb-7.0.13.Final.jar:] at   org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke (WebNonTxEmCloserValve.java:50)   [jboss-as-jpa-7.1.1.Final.jar: 7.1.1.Final] at   org.jboss.as.web.security.SecurityContextAssociationValve.invoke (SecurityContextAssociationValve.java:153)   [jboss-as-web-7.1.1.Final.jar: 7.1.1.Final] at   org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:155)   [jbossweb-7.0.13.Final.jar:] at   org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)   [jbossweb-7.0.13.Final.jar:] at   org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:109)   [jbossweb-7.0.13.Final.jar:] at   org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:368)   [jbossweb-7.0.13.Final.jar:] at   org.apache.coyote.http11.Http11Processor.process (Http11Processor.java:877)   [jbossweb-7.0.13.Final.jar:] at   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process (Http11Protocol.java:671)   [jbossweb-7.0.13.Final.jar:] at   org.apache.tomcat.util.net.JIoEndpoint $ Worker.run (JIoEndpoint.java:930)   [jbossweb-7.0.13.Final.jar:] at java.lang.Thread.run (Unknown Source)   [rt.jar: 1.7.0_60]

My Bean AgenciesMB.java:

package managedbean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.event.ValueChangeEvent;
import javax.servlet.http.HttpSession;

import model.Ads;
import model.Agencias;
import model.dao.AgenciasDao;
import model.dao.AdsDao;

import org.primefaces.context.RequestContext;
import org.primefaces.event.RowEditEvent;

import util.JasperImpressao;


@ViewScoped
@ManagedBean(name = "agenciasMB")
public class AgenciasMB implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -1968663509271177335L;
    /**
         * 
         */

    private String mensagem = "";
    private Agencias agencias = new Agencias();
    private AgenciasDao dao = new AgenciasDao();
    private Date current;

    private List<Agencias> lista = new ArrayList<Agencias>();
    private Agencias nenhum = new Agencias();

    private List<Ads> listaAds = new ArrayList<Ads>();

    public void onEdit(RowEditEvent event) {
        Agencias ag = ((Agencias) event.getObject());       
        //System.out.println(ag.toString());        
        /*
        if (dao.atualizar(ag) == null)
            this.setMensagem("Erro ao atualizar agência");
        else
            this.setMensagem("Dados atualizados com sucesso.");
            */
        if (dao.gravar(ag) == null)
            this.setMensagem("Erro ao atualizar agência");
        else
            this.setMensagem("Dados atualizados com sucesso.");
    }

    public void incluir() {

        if (dao.gravar(agencias) == null)
            this.setMensagem("Erro ao salvar Agencia");
        else
            this.setMensagem("Dados salvos com sucesso.");

    }


    public Agencias getAgencias() {     
        return agencias;
    }

    public void metodo() {
        /*FacesContext fc = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
        System.out.println("coloquei na sessão: "+agencias.getId());
        session.setAttribute("ID_USUARIO", agencias.getId());*/
        Agencias ag2 = new Agencias();

        System.out.println("blablabla: " + agencias.getId());
    }


    public void setAgencias(Agencias agencias) {
        this.agencias = agencias;
    }

    public AgenciasDao getDao() {
        return dao;
    }

    public void setDao(AgenciasDao dao) {
        this.dao = dao;
    }


    public List<Ads> getListaAds() {
        if(listaAds.isEmpty()){
            listaAds = new AdsDao().todos();
        }
        return listaAds;
    }

    public void setListaAds(List<Ads> listaAds) {
        this.listaAds = listaAds;
    }

    public String retornaSimOuNao(int simOuNao) {
        //UPDATE agencias SET servidoresConv = 3 WHERE servidoresConv is NULL
        //se for 3, não está cadastrado
        //System.out.println(this.getLista().toString());       
        if (simOuNao == 1){
            return "Sim";
        }           
        if (simOuNao == 0) {
            return "Não";
        }
        else return "";

    }

    public void onCancel(RowEditEvent event) {
        //Não apagar, apenas não realiza ação nenhuma.
    }

    public String getMensagem() {
        return mensagem;
    }

    public void setMensagem(String mensagem) {
        this.mensagem = mensagem;
    }

    public List<Agencias> getLista() {

        if (lista.isEmpty()) {
            //lista = dao.listar();
            lista = new AgenciasDao().listarOrdenado();
        }

        return lista;
    }

    public void imprimir(){

        Map<String, Object> parameters = new HashMap<String, Object>();     
        JasperImpressao jp = new JasperImpressao(); 

        jp.imprimirRelatorioPdf(parameters, "report3.jasper");

    }

    public void imprimirAgencia(){

        Map<String, Object> parameters = new HashMap<String, Object>();     
        parameters.put("codigo", agencias.getId());

        JasperImpressao jp = new JasperImpressao();

        jp.imprimirRelatorioPdf(parameters, "agencia.jasper");

    }


    public void setLista(List<Agencias> lista) {
        this.lista = lista;
    }


    public Agencias getNenhum() {
        Long id;
        id = (long) 5;
        nenhum = new AgenciasDao().pesquisarPorId(id);
        return nenhum;
    }

    public void setNenhum(Agencias nenhum) {
        this.nenhum = nenhum;
    }

    public Date getCurrent() {
        return current;
    }

    public void setCurrent(Date current) {
        this.current = current;
    }

    public void importar(String msg) {  
        System.out.println("imopo");
        RequestContext context = RequestContext.getCurrentInstance();
                context.execute("alert(msg)");  
//            RequestContext.getCurrentInstance().execute("alert (\"teste\")");  
        }  


    String action;

    //action listener event
    public void attrListener(ActionEvent event){

    action = (String)event.getComponent().getAttributes().get("action");

    }

  //get value from "f:param"    
    public String getIpParam(FacesContext fc){    
        Map<String,String> params = fc.getExternalContext().getRequestParameterMap();    
        return params.get("enderecoip");    
    }    

    public void outcome(){           
        FacesContext fc = FacesContext.getCurrentInstance();    
        //System.out.println("MeuTeste: "+getIdProfessorParam(fc));    

    }    



    public void buttonAction2() {
        FacesContext fc = FacesContext.getCurrentInstance();    
        String ip = getIpParam(fc);        

        try {
            String[] command = { "cmd", "/k", "start", "ping", "-t", ip };
            Process process = Runtime.getRuntime().exec(command);
        } catch (IOException e) {
            e.printStackTrace();
        }
    //  System.out.println(ip);
    }

    public void addMensagem(String msg1, String msg2) {
        FacesContext.getCurrentInstance().addMessage("msgDM", new FacesMessage(FacesMessage.SEVERITY_INFO, msg1, msg2));
    }

    public void info() {        
        FacesContext fc = FacesContext.getCurrentInstance();    
        String ip = getIpParam(fc);
        String pingCmd = "ping " + ip + " -n 10";

        try {
            Runtime r = Runtime.getRuntime();
            Process p = r.exec(pingCmd);            

            BufferedReader in = new BufferedReader(new
            InputStreamReader(p.getInputStream(),"ISO-8859-1"));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                FacesContext.getCurrentInstance().addMessage("messages2", new FacesMessage(FacesMessage.SEVERITY_INFO, "Ping: ", inputLine));
            }
            in.close();



        } catch (IOException e) {
            System.out.println(e);            
        }
    }

    public String buttonAction() {      
        FacesContext fc = FacesContext.getCurrentInstance();    
        String ip = getIpParam(fc);    
        String pingResult = "";

        String pingCmd = "ping " + ip + " -n 10";
        System.out.println(pingCmd);
        try {
            Runtime r = Runtime.getRuntime();
            Process p = r.exec(pingCmd);            

            BufferedReader in = new BufferedReader(new
            InputStreamReader(p.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                System.out.println(inputLine);
                pingResult += inputLine;
            }
            in.close();
            return pingResult;




        } catch (IOException e) {
            System.out.println(e);
            return "Erro!!";
        }

    }

}

The listarti.xhtml file:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

    <ui:define name="conteudo">
        <h:form prependId="false" id="form">

            <p:growl id="messages" showDetail="true" />
            <p:messages id="messages2" showDetail="true" />

            <p:ajaxStatus>
                <f:facet name="start">
                    <h:graphicImage value="ajax-loading-bar.gif" />
                </f:facet>
            </p:ajaxStatus>

            <p:dataTable id="dataTable" var="ti" value="#{agenciasMB.lista}"
                rowStyleClass="#{empty ti.ip ? 'esconder' : null}" editable="true"
                paginator="true" rows="45" style="width:''%" lazy="true"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                rowsPerPageTemplate="10,15,45,300">

                <f:facet name="header">
                   Departamento de Tecnologia da Informação (Procergs: 0800-6469191)
                </f:facet>

                <p:commandButton value="Info" id="info"
                    actionListener="#{agenciasMB.info}" update="messages">
                    <f:param name="enderecoip" value="meuip" />
                </p:commandButton>

                <!--                <p:ajax event="rowEdit" listener="#{agenciasMB.onEdit}" -->
                <!--                    update=":form:messages"  /> -->
                <p:ajax event="rowEdit" listener="#{agenciasMB.onEdit}"
                    update=":form:messages" />
                <p:ajax event="rowEditCancel" listener="#{agenciasMB.onCancel}"
                    update=":form:messages" />

                <p:column filterBy="#{ti.agencia}" headerText="Agência" filterMatchMode="contains" style="width:103px">
                    <f:facet name="header">
                        <h:outputText value="Agência" />
                    </f:facet>
                    <h:outputText value="#{ti.agencia}" />
                </p:column>

                <p:column style="width:95px">
                    <f:facet name="header">
                        <h:outputText value="IP" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.ip}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{ti.ip}" label="IP" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="width:85px">
                    <f:facet name="header">
                        <h:outputText value="Login" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.login}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{ti.login}" label="Login" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column filterBy="#{ti.rede}" headerText="Rede"
                    filterMatchMode="contains" style="width:95px">
                    <f:facet name="header">
                        <h:outputText value="Rede" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.rede}" />
                        </f:facet>
                        <f:facet name="input">
                            <h:selectOneMenu value="#{ti.rede}">
                                <f:selectItem itemLabel="ADSL" itemValue="ADSL" />
                                <f:selectItem itemLabel="PREFEITURA" itemValue="PREFEITURA" />
                                <f:selectItem itemLabel="PROCERGS" itemValue="PROCERGS" />
                            </h:selectOneMenu>
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="width:80px">
                    <f:facet name="header">
                        <h:outputText value="Velocidade ADSL" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.velocidadeadsl}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{ti.velocidadeadsl}" label="Velocidade ADSL" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="width:95px">
                    <f:facet name="header">
                        <h:outputText value="Rede Procergs / Nº ADSL" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.redeadsl}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{ti.redeadsl}"
                                label="Rede Procergs / Nº ADSL" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="width:90px">
                    <f:facet name="header">
                        <h:outputText value="Telefone" />
                    </f:facet>
                    <h:outputText value="#{ti.telefone}" />
                </p:column>

                <p:column style="width:90px">
                    <f:facet name="header">
                        <h:outputText value="Coordenador" />
                    </f:facet>
                    <h:outputText value="#{ti.coordenador}" />
                </p:column>

                <p:column style="width:110px">
                    <f:facet name="header">
                        <h:outputText value="Endereço" />
                    </f:facet>
                    <h:outputText value="#{ti.endereco}" />
                </p:column>

                <p:column style="width:90px">
                    <f:facet name="header">
                        <h:outputText value="Horário" />
                    </f:facet>
                    <h:outputText value="#{ti.horario}" />
                </p:column>

                <p:column style="text-align: center;width:95px" sortBy="#{ti.tunel}">
                    <f:facet name="header">
                        <h:outputText value="Túnel" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.tunel}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{ti.tunel}" label="Túnel" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="text-align: center;width:95px"
                    sortBy="#{ti.usuarioTunel}">
                    <f:facet name="header">
                        <h:outputText value="Usuário do Túnel" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.usuarioTunel}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{ti.usuarioTunel}" label="Túnel" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="text-align: center;width:95px"
                    sortBy="#{ti.numeroChamado}">
                    <f:facet name="header">
                        <h:outputText value="Nº Chamado" />
                    </f:facet>
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.numeroChamado}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{ti.numeroChamado}" label="Nº Chamado" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column headerText="Data Chamado"
                    style="text-align: center;width:90px">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.dataChamado}"
                                rendered="#{not empty ti.numeroChamado}">
                                                            <f:convertDateTime dateStyle="date" pattern="dd/MM/yyyy" />
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </f:facet>
                        <f:facet name="input">
                            <p:inputMask value="#{ti.dataChamado}" mask="99/99/9999"
                                label="Data do Chamado">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </p:inputMask>

                                                    <p:calendar id="date" readonlyInput="true" value="#{ti.dataChamado}" pattern="dd/MM/yyyy" mindate="#{agenciasMB.current}" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column headerText="Usuário" style="text-align: center;width:60px">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{ti.usuario}" rendered="#{not empty ti.numeroChamado}" />
                        </f:facet>
                        <f:facet name="input">
                            <h:selectOneMenu value="#{ti.usuario}">
                                <f:selectItem itemLabel="Selecione" itemValue="0" />
                                <f:selectItem itemLabel="Adriano" itemValue="Adriano" />
                                <f:selectItem itemLabel="Cléber" itemValue="Cléber" />
                                <f:selectItem itemLabel="Flávio" itemValue="Flávio" />
                                <f:selectItem itemLabel="Luis" itemValue="Luis" />
                                <f:selectItem itemLabel="Roger" itemValue="Roger" />
                            </h:selectOneMenu>
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column>
                    <f:facet name="header">
                        <h:outputText value="Observaçao" />
                    </f:facet>
                    <p:cellEditor id="obs">
                        <f:facet name="output">
                            <h:outputText value="#{ti.obs}"
                                rendered="#{not empty ti.numeroChamado}" />
                        </f:facet>
                        <f:facet name="input">
                                                        <p:inputText value="#{ti.obs}"
                                                            label="Observação"   />
                            <p:inputTextarea rows="5" cols="30" value="#{ti.obs}"
                                counter="display" maxlength="255" counterTemplate="{0}"
                                autoResize="true" />
                            <h:outputText id="display" />
                        </f:facet>
                    </p:cellEditor>

                </p:column>

                                    http://www.primefaces.org/showcase/ui/ajax/status.xhtml
                <p:column style="width:60px">
                    <p:commandButton value="Ping" id="ajax" update=":form:messages2"
                        actionListener="#{agenciasMB.info}"
                        styleClass="ui-priority-primary">
                        <f:param name="enderecoip" value="#{ti.ip}" />
                    </p:commandButton>
                </p:column>

                <p:column style="width:20px">
                    <p:rowEditor>
                    </p:rowEditor>
                </p:column>

            </p:dataTable>

        </h:form>

    </ui:define>

</ui:composition>
    
asked by anonymous 25.07.2016 / 20:33

0 answers