xhtml:
<p:repeat var="foto" value="#{registroMB.registro.fotosAsList}">
<h:link value="#{imagemMB.foto}" target="_blank">
<p:graphicImage style="margin-top:10px;margin-bottom:20px;"
class="col-md-6 col-sm-8 col-xs-12 " value="#{imagemMB.foto}" >
<f:param name="nomeFoto" value="#{foto.nome}" />
<f:param name="dataRegistro" value="#{registroMB.registro.data.timeInMillis}" />
</p:graphicImage>
</h:link>
</p:repeat>
ImageMB
public DefaultStreamedContent getFoto(){
FacesContext context = FacesContext.getCurrentInstance();
String nomeFoto = context.getExternalContext().getRequestParameterMap().get("nomeFoto");
String dataMillis = context.getExternalContext().getRequestParameterMap().get("dataRegistro");
Calendar c = GregorianCalendar.getInstance();
if (null == nomeFoto) {
return new DefaultStreamedContent();
}else{
try {
c.setTimeInMillis(Long.parseLong(dataMillis));
RegistroRemote bean = LookupUtil.lookupRegistroBean();
FotoDTO foto = bean.buscarFoto(nomeFoto, c.getTime());
DefaultStreamedContent defaultStreamedContent = new DefaultStreamedContent(new ByteArrayInputStream(foto.getFoto()));
return defaultStreamedContent;
} catch (ExcecaoIntegracao e) {
LOG.error(e.getMessage());
Util.montaMensagem(FacesMessage.SEVERITY_ERROR, "Ocorreu um erro ao buscar a foto.", false);
}
return null;
}
}
Images are normally displayed in <p:graphicImage>
but when I click the link generated by the <h:link value="#{imagemMB.foto}" target="_blank">
tag, a new tab opens in the browser showing a representation of the bytes, rather than the image. I understand that this happens because I'm sending a stream to the browser tab and not an image, my intention is to open a new tab where the image can be viewed in real size.
Is there any way to "make the browser understand" that stream and display the image?