Get object when clicking on a commandLink in DataTable

1

I'm trying to pick up an object by clicking on a commandLink which is in each of the DataTable column, but always the nullPointerException error. Can someone 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());
    }
    
asked by anonymous 11.06.2015 / 21:47

1 answer

0

Techies, your problem is to use actionListener while the correct one would be just action .

The problem with actionListener is that it runs before action .

Your code would look like:

<p:commandLink id="ajax"  ajax="false" process="@this"
    action="#{controleAuditoriaBean.prepDownload}" value="#{controleAuditoria.caminhoArquivo}">
            <f:setPropertyActionListener
                target="#{controleAuditoriaBean.solicitacoesBD}"
                            value="#{controleAuditoria}" />                         
                    <p:fileDownload value="#{controleAuditoriaBean.download}" />    
</p:commandLink>
    
11.06.2015 / 21:57