0

Iam fetching datatable from database. in database i have one column called upload image. After fetching all values from mysql database to datatable when i click on graphic image in file upload column it is displaying pop up without content means we are unable to display the popup file/image.

 WARNING: /pages/filter.xhtml @193,106 target="#{fileFilterBean.pdfId}": Error writing 'pdfId' on type com.neorays.fms.controller.FileFilterBean
    javax.el.ELException: /pages/filter.xhtml @193,106 target="#{fileFilterBean.pdfId}": Error writing 'pdfId' on type com.neorays.fms.controller.FileFilterBean
        at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:139)
        at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:211)
        at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
        at javax.faces.component.UICommand.broadcast(UICommand.java:300)
        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: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 com.neorays.fms.filter.AuthFilter.doFilter(AuthFilter.java:63)
        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:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.el.ELException: Error writing 'pdfId' on type com.neorays.fms.controller.FileFilterBean
        at javax.el.BeanELResolver.setValue(BeanELResolver.java:153)
        at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
        at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
        at org.apache.el.parser.AstValue.setValue(AstValue.java:217)
        at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:252)
        at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
        ... 33 more
    Caused by: java.lang.NullPointerException
        at com.neorays.fms.controller.FileFilterBean.setPdfId(FileFilterBean.java:186)
        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:497)
        at javax.el.BeanELResolver.setValue(BeanELResolver.java:142)
        ... 38 more

    else partaaa@gmail.comJul 11, 2015 2:25:19 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
    SEVERE: java.lang.NullPointerException
        at com.neorays.fms.controller.FileFilterBean.setPdfId(FileFilterBean.java:186)
        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:497)
        at javax.el.BeanELResolver.setValue(BeanELResolver.java:142)
        at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
        at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
        at org.apache.el.parser.AstValue.setValue(AstValue.java:217)
        at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:252)
        at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
        at com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:211)
        at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
        at javax.faces.component.UICommand.broadcast(UICommand.java:300)
        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: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 com.neorays.fms.filter.AuthFilter.doFilter(AuthFilter.java:63)
        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:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

This is my xhtml page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">

<h:form id="form">
<p:dataTable id="tbl" var="fileDTVar"
            value="#{fileFilterBean.allFileListForFiltering}" widgetVar="carsTable"
            emptyMessage="No files found with given criteria"
            rowIndexVar="rowIndex"
            filteredValue="#{fileFilterBean.valuesAfterFiltering}"
            style="width:auto;height:auto;">

            <p:column headerText="#{msg.FILE_UPLOAD}" style="font-size: 80%;width:45px;">
            <p:commandLink oncomplete="PF('test').show()" update=":form:dialog">
                <f:setPropertyActionListener value="#{fileDTVar.fileSerialNumber}" target="#{fileFilterBean.pdfId}"/>
                <p:graphicImage value="pdf.png" width="30" height="20" alt="Please refresh" cache="false"/>
            </p:commandLink>
            </p:column>
            <p:column headerText="#{msg.REMARKS}"  style="font-size: 80%;width:80px;">
                <h:outputText value="#{fileDTVar.fileRemarks}" />
            </p:column>

        </p:dataTable>
    <p:dialog widgetVar="test" id="dialog">
        <p:media value="#{fileFilterBean.outPutPdfToDisplay}" width="700px" height="700px" player="pdf"/>
    </p:dialog>
    </h:form></html>

This is my bean

package com.neorays.fms.controller;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.springframework.stereotype.Component;

import com.lowagie.text.Image;
import com.neorays.fms.dao.entity.Category;
import com.neorays.fms.dao.entity.Filemanagement;
import com.neorays.fms.dao.entity.Status;

@Component
@ManagedBean
public class FileFilterBean extends BaseBean{

    private List<Filemanagement> allFileList;

    private List<Filemanagement> filteredFiles;

    private List<Filemanagement> filList;

    private List<Filemanagement> allFileListForFiltering;

    private List<Filemanagement> valuesAfterFiltering;

    private String smgeId;

    private String pdfId;

    private StreamedContent outPutPdfToDisplay = null;

    private List<Filemanagement> fileListForQueryingStatusAndCategory; 
    private String category;
    private String status;


    public String viewAll() {
        allFileList = baseServiceImpl.fetchAll(Filemanagement.class);
        return "viewAll";
    }

    public String search() {
        allFileListForFiltering = baseServiceImpl.fetchAll(Filemanagement.class);
        return "filter";
    }

    public String fetchAllCategory() 
    {
        Status fetchStatusById = baseServiceImpl.fetchEntityById(Status.class,Integer.parseInt(status));
        System.out.println(fetchStatusById.getStatusId());
        System.out.println(fetchStatusById.getStatusName());
        /*Category fetchCategoryById = baseServiceImpl.fetchEntityById(Category.class, Integer.parseInt(category));
        System.out.println(fetchCategoryById.getCategoryId());
        System.out.println(fetchCategoryById.getCategoryName());*/

        fileListForQueryingStatusAndCategory = baseServiceImpl.fetchAllCatagory(fetchStatusById);
        return "fetchAllCategory";
    }

    public void resetValues() {
        this.status = null;
        this.category = null;
    }

    public String back(){
        resetValues();
        return "fileregister";
    }

    public String addNewFile() {
        return "fileregister";
    }
    public List<Filemanagement> getAllFileList() {
        return allFileList;
    }

    public void setAllFileList(List<Filemanagement> allFileList) {
        this.allFileList = allFileList;
    }

    public List<Filemanagement> getFilteredFiles() {
        return filteredFiles;
    }

    public void setFilteredFiles(List<Filemanagement> filteredFiles) {
        this.filteredFiles = filteredFiles;
    }

    public List<Filemanagement> getFilList() {
        return filList;
    }

    public void setFilList(List<Filemanagement> filList) {
        this.filList = filList;
    }

    public List<Filemanagement> getAllFileListForFiltering() {
        return allFileListForFiltering;
    }

    public void setAllFileListForFiltering(List<Filemanagement> allFileListForFiltering) {
        this.allFileListForFiltering = allFileListForFiltering;
    }

    public List<Filemanagement> getValuesAfterFiltering() {
        return valuesAfterFiltering;
    }

    public void setValuesAfterFiltering(List<Filemanagement> valuesAfterFiltering) {
        this.valuesAfterFiltering = valuesAfterFiltering;
    }

    public List<Filemanagement> getFileListForQueryingStatusAndCategory() {
        return fileListForQueryingStatusAndCategory;
    }

    public void setFileListForQueryingStatusAndCategory(
            List<Filemanagement> fileListForQueryingStatusAndCategory) {
        this.fileListForQueryingStatusAndCategory = fileListForQueryingStatusAndCategory;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getSmgeId() {
        return smgeId;
    }

    public void setSmgeId(String smgeId) {
        System.out.println("inside setSmgeId");
        this.smgeId = smgeId;
    }

    public StreamedContent getOutPutPdfToDisplay() {
        System.out.println("inside getOutPutPdfToDisplay");
        if (FacesContext.getCurrentInstance().getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
            System.out.println("inside if of getOut");
            // So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
            return new DefaultStreamedContent();
        }
        else {
            System.out.println("inside else of getOut");
            // So, browser is requesting the image. Get ID value from actual request param.
            String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");
            Filemanagement fetchEntityById = baseServiceImpl.fetchEntityById(Filemanagement.class, Integer.valueOf(id));
            byte[] fileScanned = fetchEntityById.getFileScanned();
            return new DefaultStreamedContent(new ByteArrayInputStream(fileScanned));
        }
    }

    public void setOutPutPdfToDisplay(StreamedContent outPutPdfToDisplay) {
        System.out.println("inside setOutPutPdfToDisplay");
        this.outPutPdfToDisplay = outPutPdfToDisplay;
    }

    public String getPdfId() {
        return pdfId;
    }

    public void setPdfId(String pdfId) {
        this.pdfId = pdfId;
        System.out.println("inside pdfId. Is is "+pdfId);
        Filemanagement entityById = baseServiceImpl.fetchEntityById(Filemanagement.class, Integer.parseInt(pdfId));
        byte[] fileScanned = entityById.getFileScanned();
        try {
            outPutPdfToDisplay.getStream().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        outPutPdfToDisplay = new DefaultStreamedContent(new ByteArrayInputStream(fileScanned),"application/pdf");
    }
}
  • You've provided a whole pile of code within your question. You might find that you receive prompt and better answers if you instead only provided the section of your code in which you suspect there is a problem. – ankh-morpork Jul 11 '15 at 11:06
  • Seems you have a `NullPointerException`. Apparently your value is null. – RealSkeptic Jul 11 '15 at 11:13
  • I closed this question as duplicate of http://stackoverflow.com/a/24100776, because you basically asked "Why do I get a NullPointerException?" along with a code dump (way more than half is irrelevant), instead of asking "Why is this variable null?" along with a [MCVE](http://stackoverflow.com/help/mcve). First learn what exactly a NPE is and then we can advance. In the meanwhile, it wouldn't be a bad idea either to take a pause on Java EE and practice a bit more with basic Java SE, so you can easier understand exceptions of `java.lang` package (and practice reading stack traces too). – BalusC Jul 11 '15 at 11:14

0 Answers0