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:

<servlet>
        <servlet-name>FileServlet</servlet-name>
        <display-name>File servlet</display-name>
        <description>Servlet used to view or download an Image or
document</description>
       
<servlet-class>main.org.jboss.portlet.milestone.servlet.FileServlet</servlet-class>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>FileServlet</servlet-name>
        <url-pattern>/FileServlet/*</url-pattern>
    </servlet-mapping>

and the call for me from a jsp:
<h:graphicImage value="/FileServlet/?file_id=#{datatype.fileID}"/>


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.
>>
>> <context-param>
>>        
>> <param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
>>         <param-value>false</param-value>
>>     </context-param>
>> 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:
>> <lifecycle>
>>
>> <phase-listener>main.org.jboss.portlet.milestone.portlet.phaselistener.ImagePhaseListener</phase-listener>
>>         </lifecycle>
>>
>> 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:
>> >
>> > <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#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
> 
> 

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

Reply via email to