Primefaces file download only works when I use the default constructor
<p>I download a file using HttpURLConnection, then I want to give the user the option to download that file. I use this primefaces example <a href="http://www.primefaces.org/showcase/ui/file/download.xhtml" rel="nofollow">http://www.primefaces.org/showcase/ui/file/download.xhtml</a>. </p>

<p>My issue is that if I download hard coded file via the default constructor as it's mentioned in the example, everything work. but if  I pass the filename to constructor that accept param, I get a null pointer. </p>

<p>Here is the code with both constructor (only the default constructor with the hard coded file works)</p>

<pre><code>@ManagedBean

public class FileDownloadView {

    private StreamedContent file;
    private InputStream stream;
    private String fileName;

    public String getFileName() {
        return fileName;
    }


    public FileDownloadView() {
        InputStream stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/tmp/1kb.txt");
        file = new DefaultStreamedContent(stream, "text/plain", "text.txt");
        System.out.println("fileName......." + "test.txt");

    }

    public  FileDownloadView(String fileName) {
        this.fileName = fileName;

        InputStream stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/tmp/" + fileName);
        this.fileName = fileName;
        file = new DefaultStreamedContent(stream, "text/plain", fileName);
        System.out.println("fileName......." + file.getName());

    }

    public StreamedContent getFile() {
        System.out.println("file  "+file.getName());

        return file;
    }
}
</code></pre>

<p>And here how I am pulling the file
</p>

<pre><code>     &lt;p:commandButton value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop);" icon="ui-icon-arrowthick-1-s"&gt;
                &lt;p:fileDownload value="#{fileDownloadView.file}" /&gt;
            &lt;/p:commandButton&gt;

            &lt;p:outputLabel value="#{fileDownloadView.fileName}"/&gt;
        &lt;/h:form&gt;
        &lt;script type="text/javascript"&gt;
                                       function start() {
                                           PF('statusDialog').show();
                                       }

                                       function stop() {
                                           PF('statusDialog').hide();
                                       }
        &lt;/script&gt;
</code></pre>