fileDowload exception

UI Components for JSF
Post Reply
jbn1981
Posts: 17
Joined: 10 May 2011, 13:00

07 Jul 2011, 14:54

Hi, I' trying to download a file, just like showcase example does, but I get this exception:

java.lang.NullPointerException
org.primefaces.component.filedownload.FileDownloadActionListener.processAction(FileDownloadActionListener.java:59)
javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:777)
javax.faces.component.UICommand.broadcast(UICommand.java:300)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)

xhtml code:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:p="http://primefaces.prime.com.tr/ui"
		xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head>
		<title>OTT</title>
	</h:head>
	<h:body>
		<h:form>
			<p:commandButton value="Download" ajax="false">
            	<p:fileDownload value="#{fileDownloadController.file}" />
            </p:commandButton>						
		</h:form>
	</h:body>
</html>
FileDownloadController code:

Code: Select all

import java.io.InputStream;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

@ManagedBean
@SessionScoped
public class FileDownloadController {

        private StreamedContent file;
        
        public FileDownloadController() {
                InputStream stream = this.getClass().getResourceAsStream("e:\\mipdf.pdf");
                file = new DefaultStreamedContent(stream, "application/pdf", "mipdf.pdf");
        }
        
        public StreamedContent getFile() {
                return file;
        }

        public void setFile(StreamedContent file) {
                this.file = file;
        }
}
The file mipdf.pdf is in unit e:


Thanks!
Primefaces 2.2.1 | Mojarra 2.0.4 | Tomcat 6

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 39 guests