You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Hoehmann, Andreas" <an...@siemens.com> on 2008/04/01 10:29:10 UTC

AW: Exclude servlet-response from extension-filter

> -----Ursprüngliche Nachricht-----
> Von: simon [mailto:simon.kitching@chello.at] 
> Gesendet: Montag, 31. März 2008 21:50
> An: MyFaces Discussion
> Betreff: Re: Exclude servlet-response from extension-filter
> 
> 
> On Mon, 2008-03-31 at 17:42 +0200, Hoehmann, Andreas wrote:
> > Hello,
> > 
> > How can i exclude the response of a download-action for the
> > extension-filter?
> > 
> > My bean write the result directly to the faces-response:
> > 
> > private boolean writeOutContent(final HttpServletResponse res, final
> > File content, final String theFilename) {
> >     boolean result = true;
> >     if (content != null) {
> >       try {
> >         res.reset();
> >         final WritableByteChannel writeChannelOut =
> > Channels.newChannel(res.getOutputStream());
> >         final ReadableByteChannel readChannelIn =
> > Channels.newChannel(new FileInputStream(content));
> >         res.setHeader("Pragma", "no-cache");
> >         res.setDateHeader("Expires", 0);
> >         // set content type so that the browser shows xml 
> filter in save
> > dialog
> >         res.setContentType("text/xml");
> >         res.setHeader("Content-disposition", "attachment; 
> filename=" +
> > theFilename);
> >         ChannelTools.fastChannelCopy(readChannelIn, 
> writeChannelOut);
> >       } catch (final IOException e) {
> >         result = false;
> >       }
> >     } else {
> >       result = false;
> >     }
> >     return result;
> >   }
> > 
> >   private String download() {
> >     final FacesContext facesContext = 
> FacesContext.getCurrentInstance();
> >     writeOutContent(getServletResponse(), new File(this.filename),
> > getFilename());
> >     facesContext.responseComplete();
> >     return null;
> >   }
> > 
> > I found these lines in ExtensionFilter:
> > 
> > public boolean isValidContentType(String contentType)
> >     {
> >         return contentType.startsWith("text/html") ||
> >                 contentType.startsWith("text/xml") ||
> >                 contentType.startsWith("application/xhtml+xml") ||
> >                 contentType.startsWith("application/xml");
> >     }
> > 
> > I must return a text/xml but i dont want filter the content with the
> > extension-filter. Is this possible?
> > 
> > My web.xml:
> > 
> > <filter-mapping>
> >     <filter-name>MyFacesExtensionsFilter</filter-name>
> >     <servlet-name>FacesServlet</servlet-name>
> >   </filter-mapping>
> >   <filter-mapping>
> >     <filter-name>MyFacesExtensionsFilter</filter-name>
> >     <url-pattern>*.jsf</url-pattern>
> >   </filter-mapping>
> 
> Why does it matter? If your page contains no components that register
> resources to be inserted, then the output you generate will not be
> modified.

I got a error from myfaces:

10:18:34 ERROR - org.apache.myfaces.renderkit.html.util.ReducedHTMLParser:653 - Malformed end tag at line 41; skipping p
arsing

I want separate my download-function (rich:htmlCommandlink) which returns a xml-file from the rest of my application/ui.
It should doesn't matter which other components used on the page with the download-link. The download-bean reset the 
faces-response and return a none-faces-xml-content ... 

exists a "Best Practice" for such a scenario?

> 
> If for some reason you really care, then you can switch to using the
> StreamingAddResources implementation rather than the 
> DefaultAddResources
> one. This has some limitations (esp. not supporting components
> registering stylesheets for themselves), but does not buffer output.
> 

I don't want code a face-component ... So this is not a solution for my problem :-)

> This is all explained in the javadoc for the ExtensionsFilter class in
> svn trunk; see the current javadocs on the tomahawk website.
> 
> Regards,
> Simon

Regards
hoehmi