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.

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.

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

Regards,
Simon

Reply via email to