1
I’m trying to catch an object by clicking on a commandLink that is in each column of Datatable, but always from the nullPointerException error. Can anyone help?
I’m doing it this way:
<p:commandLink id="ajax"  ajax="false" process="@this"
    actionListener="#{controleAuditoriaBean.prepDownload}" value="#{controleAuditoria.caminhoArquivo}">
            <f:setPropertyActionListener
                target="#{controleAuditoriaBean.solicitacoesBD}"
                            value="#{controleAuditoria}" />                         
                    <p:fileDownload value="#{controleAuditoriaBean.download}" />    
</p:commandLink>
Method:
public void prepDownload() throws Exception {
        System.out.println("Caminho "+solicitacoesBD.getCaminhoArquivo());
        File file = new File(solicitacoesBD.getCaminhoArquivo());
        InputStream input = new FileInputStream(file);
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(file.getName()), file.getName()));
        System.out.println("PREP = " + download.getName());
    }
						
It worked, but I have to click 2x on the link to start the download of the file. Your click 1x it takes the right object but the download does not start.
– DiegoAugusto
@Techies You can go back to
actionListenerand tries to pass the value by parameter instead off:setPropertyActionListener, experiment!– Maicon Carraro
To pass by parameter do not need to use the
f:setPropertyActionListener?– DiegoAugusto
It depends on the version of your jsf, which is? :)
– Maicon Carraro
I believe it’s 2.2
– DiegoAugusto
You can do it
actionListener="#{controleAuditoriaBean.prepDownload(controleAuditoria)}"– Maicon Carraro
I went back to the
actionListener, you just need to change your methodprepDownloadto receive this type of parameter– Maicon Carraro
to receive this parameter in my method I use requestContext?
– DiegoAugusto
or just put the object in the method to receive this parameter? for example
prepDownload(Auditoria a)– DiegoAugusto
@Techies only put the object in the method, like its last example
– Maicon Carraro
Thank you again Maicon. You have helped me a lot.
– DiegoAugusto