Check if there is a file in a particular jsf rendered folder

Asked

Viewed 218 times

2

People I am saving image in a certain project folder and I need to check if this file exists in the folder. Was using a command as below:

rendered="Fotos/#{consultaFuncionariosBean.pessoaModel.codigo != null}.png"

But it didn’t work. Does anyone know how I can fix this?

Resolved as Below.

Method.

public boolean existeArquivo(String file) {
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    String nomeSaida = externalContext.getRealPath("") + "resources" + File.separator + "Fotos" + File.separator + file + ".png";
    File Arqs = new File(nomeSaida);
    boolean success = Arqs.exists();
    return success;
}

Form.

    <p:graphicImage rendered="#{photoCamBean.existeArquivo(consultaFuncionariosBean.pessoaModel.codigo)==false}" library="Fotos" name="Modelo.jpg" cache="false"/>
    <p:graphicImage rendered="#{photoCamBean.existeArquivo(consultaFuncionariosBean.pessoaModel.codigo)==true}" name="Fotos/#{consultaFuncionariosBean.pessoaModel.codigo}.png" cache="false"/>

1 answer

1


The attribute rendered is Boolean.


Do something like:

@ManagedBean
public class TesteMB {

    private File arquivo;
    private boolean arquivoExiste;

    public boolean getArquivoExiste() {
        return arquivo != null;
    }
}

And then:

rendered="#{testeMB.arquivoExiste}"

Or to make it easier, you can check directly in the view:

@ManagedBean
public class TesteMB {

    private File arquivo;

    public File getArquivo() {
        return arquivo;
    }
}

And then:

rendered="#{testeMB.arquivo != null}"
  • 1

    Thank you Igor Resolvi as posted above and according to your grateful help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.