myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omidh <om...@gmx.de>
Subject h:graphicImage and Servlets
Date Tue, 15 May 2007 11:09:34 GMT

Hi all,
I would like to show images in my portlet, which are saved in a Mysql db, so
I wrote a servlet
which helps to download files from the db. Now I use these servlet to
receive also the Images but 
it does not work... does anyone know a solution?

here the way I use it:

<h:graphicImage value="/FileServlet/?file_id=#{datatype.fileID}"/>
generated code: < i m g src="/MileStoneBeta/FileServlet/?file_id=1">

and here the servlet (nothing special):

protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		FacesContext fctx = getFacesContext(request, response);
		
		ValueBinding bind = FacesContext.getCurrentInstance().getApplication()
				.createValueBinding("#{facadeService}");
		if (bind == null)
			logger.fatal("ValueBinding is null");

		FacadeService bean = (FacadeService) bind.getValue(fctx);
		
		
		Integer fileId = Integer.parseInt(request.getParameter("file_id"));
		
		UFile file =
(UFile)bean.getMileStoneService().getEntryManager().loadById(UFile.class,
fileId);
		logger.debug("file="+file);
		if(file != null){
			response.setContentType(file.getContentType());
			response.setContentLength(file.getContent().length);
			response.setHeader("Content-Disposition", "attachement; filename=\"" + 
					file.getFileName() + "\"");
			if(logger.isDebugEnabled())
				logger.debug("sending file ...");
			response.getOutputStream().write(file.getContent());
			response.flushBuffer();
		}
		
	}

or is there a simple way to do it? ;)

thanks in advance,
Omid
-- 
View this message in context: http://www.nabble.com/h%3AgraphicImage-and-Servlets-tf3757832.html#a10620803
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Mime
View raw message