[RESOLVIDO] Exibir imagem fora do contexto do Projeto + JSF 2 + Primefaces 3

[quote=LeoCBS]Fala resoig

só consegui exibir minha imagem através de um Servlet

link do tutorial:


segue o código do meu Servlet, tive que fazer uma adaptação para pegar a imagem do disco invés de buscar do BD…

[code]
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Long idLugar = Long.valueOf(request.getPathInfo().substring(1));
Foto foto = null;
Context ctx;
try {
ctx = new InitialContext();
LugarBBusinessLocal bean = (LugarBBusinessLocal) ctx
.lookup(LugarBBusinessLocal.JNDI_NAME);
foto = bean.retornaImagemHome(idLugar);
} catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

	BufferedImage bufferedImg = new BufferedImage(100, 25,
			BufferedImage.TYPE_INT_RGB);
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	File imgFile = new File(foto.getDsPath());
	try {
		bufferedImg = ImageIO.read(imgFile);
		ImageIO.write(bufferedImg, "jpg", baos);
		baos.flush();
	} catch (IOException e) {
		e.printStackTrace();
	}

	response.setHeader("Content-Type",
			getServletContext().getMimeType(imgFile.getName()));
	response.setHeader("Content-Length", imgFile.length() + "");
	response.setHeader("Content-Disposition", "inline; filename=\""
			+ imgFile.getName() + "\"");

	BufferedInputStream input = null;
	BufferedOutputStream output = null;
	InputStream is = new ByteArrayInputStream(baos.toByteArray());

	try {
		input = new BufferedInputStream(is);
		output = new BufferedOutputStream(response.getOutputStream());
		byte[] buffer = new byte[8192];
		int length;
		while ((length = input.read(buffer)) > 0) {
			output.write(buffer, 0, length);
		}
	} finally {
		if (output != null)
			try {
				output.close();
			} catch (IOException logOrIgnore) {
			}
		if (input != null)
			try {
				input.close();
			} catch (IOException logOrIgnore) {
			}
	}

}[/code]

resoig, obrigado pela ajuda[/quote]

Fala Leo,

Então mano, vc testou esse metodo GET no seu MB que retorna a imagem?

public StreamedContent getFoto() { 

FacesContext context = FacesContext.getCurrentInstance(); 
HttpServletRequest myRequest = (HttpServletRequest) context.getExternalContext().getRequest(); 
String lugarID = (String) myRequest.getParameter("idLugar"); 

return new DefaultStreamedContent(new ByteArrayInputStream(metodoQueRetornaByteArray(lugarID)), "image/png" 
} 

testei sim resoig…

pra mim esse código (String) myRequest.getParameter(“idLugar”); sempre retorna null…

por isso fiz um Servlet

obrigado ae pela ajuda!

abraço!