I would like to present an image that comes from an internal image server of the company. I can access it by an internal http address. Must present it without showing this internal address in the source code, using a p.graphicImage
.
The View is here:
<p:fieldset legend="Dados pessoais">
<br/>
<p:graphicImage value="#{funcionarioEditMB.graphicText}" id="foto" cache="false">
<f:param name="id" value="#{funcionarioEditMB.bean.matricula}" />
</p:graphicImage>
<br/>
//--*-
MB related part:
//no init chamo esta função passando a matricula (this.getImagem(funcionario.getMatricula());)
public void getImagem(Integer matricula){
ByteArrayOutputStream os = null;
byte[] bytes = null;
FacesContext context = FacesContext.getCurrentInstance();
String id = context.getExternalContext().getRequestParameterMap().get("id");
try{
URL url = new URL(funcionarioBC.getImage(Integer.parseInt(id)));
BufferedImage image = ImageIO.read(url);
os = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", os);
bytes = os.toByteArray();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
// So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
graphicText = new DefaultStreamedContent();
} else {
// So, browser is requesting the image. Get ID value from actual request param.
graphicText = new DefaultStreamedContent(new ByteArrayInputStream(bytes));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private StreamedContent graphicText;
public StreamedContent getGraphicText() {
return graphicText;
}
But the image does not appear in the view. The following link is displayed: http://localhost:8080/eSGRH/javax.faces.resource/dynamiccontent.properties.jsf?ln=primefaces&pfdrid=aiHZO8v7zFQ6p%2bPffO1S1vWT2KGBHKr%2bR3guIqtplAUT4IpnxJZmHw==&id=479488&pfdrid_c=false&uid=4e51fb92-b0bc-4530-8e3c-3d28fa750563
Could someone help me to understand what is wrong?