Re: h:graphicImage and Servlets
tkanks ;) Martin Marinschek wrote: > > ok, yes, that's clear - you can't embed an attachment. > > For other files - there is a typo in your code - attachment instead of > attachment would be appropriate. > > response.setHeader("Content-Disposition", "attachment; filename=\"" + >file.getFileName() + "\""); > > regards, > > Martin > > On 5/16/07, omidh <[EMAIL PROTECTED]> wrote: >> >> Hi Martin, >> thank you for your response, >> >> the class name is correct. >> I solved it with my FileServlet now. >> The problem in the servlet was (I think) that when showing Image >> it may not be set the response.setHeader(...), now the code look like >> these >> >> To whom it may interest: >> >> protected void doGet(HttpServletRequest request, >> HttpServletResponse response) throws >> ServletException, IOException { >> >> FacesContext fctx = getFacesContext(request, response); >> >> ValueBinding bind = >> FacesContext.getCurrentInstance().getApplication() >> .createValueBinding("#{facadeService}"); >> >> FacadeService bean = (FacadeService) bind.getValue(fctx); >> >> if (logger.isDebugEnabled()) >> logger.debug("Bean=" + bean); >> >> OutputStream out = response.getOutputStream(); >> >> 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); >> if(file.getContentType().indexOf("image") == -1){ >> response.setHeader("Content-Disposition", >> "attachement; filename=\"" + >> file.getFileName() + "\""); >> } >> if(logger.isDebugEnabled()) >> logger.debug("sending file ..."); >> out.write(file.getContent()); >> out.flush(); >> out.close(); >> response.flushBuffer(); >> } >> >> as you can see the changes are minimal... >> don't forget to add the following to the web.xml: >> >> >> FileServlet >> File servlet >> Servlet used to view or download an Image or >> document >> >> main.org.jboss.portlet.milestone.servlet.FileServlet >> >> >> >> FileServlet >> /FileServlet/* >> >> >> and the call for me from a jsp: >> >> >> >> so again... thanks to anyone who responsed.. >> >> regards Omid >> >> >> >> >> Martin Marinschek wrote: >> > >> > Is the phase-listener not found at all? >> > >> > Is the class-name correct? on the first glance, I'd suspect the main. >> > is too much. >> > >> > regards, >> > >> > Martin >> > >> > On 5/16/07, omidh <[EMAIL PROTECTED]> wrote: >> >> >> >> Thank you very much for your response, >> >> On your advice I wrote an PahseListener but it doesn't work. I don't >> know >> >> if >> >> it is a config failure or not. >> >> The problem is I think that in my web.xml the Extension-filter is set >> to >> >> false. >> >> >> >> >> >> >> >> org.apache.myfaces.CHECK_EXTENSIONS_FILTER >> >> false >> >> >> >> thats because I use the tomahawk-bridge in my portlet and for these >> the >> >> Extension-filter must be shutdown. >> >> is these the reason??? >> >> >> >> in my faces-config.xml I did the following to run the phaseListener: >> >> >> >> >> >> >> main.org.jboss.portlet.milestone.portlet.phaselistener.ImagePhaseListener >> >> >> >> >> >> thanks, >> >> >> >> Omid >> >> >> >> >> >> omidh wrote: >> >> > >> >> > 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: >> >> > >> >> > >> >> > 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 == nu
Re: h:graphicImage and Servlets
ok, yes, that's clear - you can't embed an attachment. For other files - there is a typo in your code - attachment instead of attachment would be appropriate. response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getFileName() + "\""); regards, Martin On 5/16/07, omidh <[EMAIL PROTECTED]> wrote: Hi Martin, thank you for your response, the class name is correct. I solved it with my FileServlet now. The problem in the servlet was (I think) that when showing Image it may not be set the response.setHeader(...), now the code look like these To whom it may interest: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { FacesContext fctx = getFacesContext(request, response); ValueBinding bind = FacesContext.getCurrentInstance().getApplication() .createValueBinding("#{facadeService}"); FacadeService bean = (FacadeService) bind.getValue(fctx); if (logger.isDebugEnabled()) logger.debug("Bean=" + bean); OutputStream out = response.getOutputStream(); 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); if(file.getContentType().indexOf("image") == -1){ response.setHeader("Content-Disposition", "attachement; filename=\"" + file.getFileName() + "\""); } if(logger.isDebugEnabled()) logger.debug("sending file ..."); out.write(file.getContent()); out.flush(); out.close(); response.flushBuffer(); } as you can see the changes are minimal... don't forget to add the following to the web.xml: FileServlet File servlet Servlet used to view or download an Image or document main.org.jboss.portlet.milestone.servlet.FileServlet FileServlet /FileServlet/* and the call for me from a jsp: so again... thanks to anyone who responsed.. regards Omid Martin Marinschek wrote: > > Is the phase-listener not found at all? > > Is the class-name correct? on the first glance, I'd suspect the main. > is too much. > > regards, > > Martin > > On 5/16/07, omidh <[EMAIL PROTECTED]> wrote: >> >> Thank you very much for your response, >> On your advice I wrote an PahseListener but it doesn't work. I don't know >> if >> it is a config failure or not. >> The problem is I think that in my web.xml the Extension-filter is set to >> false. >> >> >> >> org.apache.myfaces.CHECK_EXTENSIONS_FILTER >> false >> >> thats because I use the tomahawk-bridge in my portlet and for these the >> Extension-filter must be shutdown. >> is these the reason??? >> >> in my faces-config.xml I did the following to run the phaseListener: >> >> >> main.org.jboss.portlet.milestone.portlet.phaselistener.ImagePhaseListener >> >> >> thanks, >> >> Omid >> >> >> omidh wrote: >> > >> > 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: >> > >> > >> > 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.se
Re: h:graphicImage and Servlets
Hi Martin, thank you for your response, the class name is correct. I solved it with my FileServlet now. The problem in the servlet was (I think) that when showing Image it may not be set the response.setHeader(...), now the code look like these To whom it may interest: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { FacesContext fctx = getFacesContext(request, response); ValueBinding bind = FacesContext.getCurrentInstance().getApplication() .createValueBinding("#{facadeService}"); FacadeService bean = (FacadeService) bind.getValue(fctx); if (logger.isDebugEnabled()) logger.debug("Bean=" + bean); OutputStream out = response.getOutputStream(); 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); if(file.getContentType().indexOf("image") == -1){ response.setHeader("Content-Disposition", "attachement; filename=\"" + file.getFileName() + "\""); } if(logger.isDebugEnabled()) logger.debug("sending file ..."); out.write(file.getContent()); out.flush(); out.close(); response.flushBuffer(); } as you can see the changes are minimal... don't forget to add the following to the web.xml: FileServlet File servlet Servlet used to view or download an Image or document main.org.jboss.portlet.milestone.servlet.FileServlet FileServlet /FileServlet/* and the call for me from a jsp: so again... thanks to anyone who responsed.. regards Omid Martin Marinschek wrote: > > Is the phase-listener not found at all? > > Is the class-name correct? on the first glance, I'd suspect the main. > is too much. > > regards, > > Martin > > On 5/16/07, omidh <[EMAIL PROTECTED]> wrote: >> >> Thank you very much for your response, >> On your advice I wrote an PahseListener but it doesn't work. I don't know >> if >> it is a config failure or not. >> The problem is I think that in my web.xml the Extension-filter is set to >> false. >> >> >> >> org.apache.myfaces.CHECK_EXTENSIONS_FILTER >> false >> >> thats because I use the tomahawk-bridge in my portlet and for these the >> Extension-filter must be shutdown. >> is these the reason??? >> >> in my faces-config.xml I did the following to run the phaseListener: >> >> >> main.org.jboss.portlet.milestone.portlet.phaselistener.ImagePhaseListener >> >> >> thanks, >> >> Omid >> >> >> omidh wrote: >> > >> > 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: >> > >> > >> > 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=\"" + >> >
Re: h:graphicImage and Servlets
Is the phase-listener not found at all? Is the class-name correct? on the first glance, I'd suspect the main. is too much. regards, Martin On 5/16/07, omidh <[EMAIL PROTECTED]> wrote: Thank you very much for your response, On your advice I wrote an PahseListener but it doesn't work. I don't know if it is a config failure or not. The problem is I think that in my web.xml the Extension-filter is set to false. org.apache.myfaces.CHECK_EXTENSIONS_FILTER false thats because I use the tomahawk-bridge in my portlet and for these the Extension-filter must be shutdown. is these the reason??? in my faces-config.xml I did the following to run the phaseListener: main.org.jboss.portlet.milestone.portlet.phaselistener.ImagePhaseListener thanks, Omid omidh wrote: > > 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: > > > 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#a10635281 Sent from the MyFaces - Users mailing list archive at Nabble.com. -- http://www.irian.at Your JSF powerhouse - JSF Consulting, Development and Courses in English and German Professional Support for Apache MyFaces
Re: h:graphicImage and Servlets
Thank you very much for your response, On your advice I wrote an PahseListener but it doesn't work. I don't know if it is a config failure or not. The problem is I think that in my web.xml the Extension-filter is set to false. org.apache.myfaces.CHECK_EXTENSIONS_FILTER false thats because I use the tomahawk-bridge in my portlet and for these the Extension-filter must be shutdown. is these the reason??? in my faces-config.xml I did the following to run the phaseListener: main.org.jboss.portlet.milestone.portlet.phaselistener.ImagePhaseListener thanks, Omid omidh wrote: > > 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: > > > 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#a10635281 Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: h:graphicImage and Servlets
An example which I used in HibernateTrace. http://jsf-comp.svn.sourceforge.net/viewvc/jsf-comp/trunk/HibernateTrace/HibernateTraceComponent/JavaSource/net/sf/jsfcomp/hibernatetrace/util/HTResourceLoaderPhaseListener.java?view=markup Regards, Mert.. On 5/15/07, omidh <[EMAIL PROTECTED]> wrote: 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: 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.
Re: h:graphicImage and Servlets
Hi, Instead of a servlet, you may use a phaselistener instead which fits better in portlet environment. Here's an example; http://www.jroller.com/page/cagataycivici?entry=phaselistener_renders_an_image_no Regards, Cagatay On 5/15/07, omidh <[EMAIL PROTECTED]> wrote: 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: 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.
h:graphicImage and Servlets
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: 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.