Personal I'm saving image to a particular project folder and I need to check if this file exists in the folder. I was using a command as below:
rendered="Fotos/#{consultaFuncionariosBean.pessoaModel.codigo != null}.png"
But it did not work. Does anyone know how I can resolve 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"/>