Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax4Jsf Filter interfering when contentType is set to 'application/pdf'

 
Augustine Chelliah
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a requirement where i need to click a command link and a PDF file to be opened in a new window. The path of the PDF file is to be taken from a database. So in the backing bean, I get the path, set the contentType to 'application/pdf' and of course writing to a new byte steam. When i run it , a new window opens but the file does not get displayed.... when i checked the logs, I think Ajax4JSF is interfering with this process..... check out the below logs..

[WebContainer : 4] DEBUG org.ajax4jsf.framework.ajax.AjaxContext - Process component tree for collect used scripts and styles
2009-08-05 04:54:22,478 [WebContainer : 4] DEBUG org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlResponseWriterImpl - No content type given, using default content type text/html
2009-08-05 04:54:22,478 [WebContainer : 4] DEBUG org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlResponseWriterImpl - No character encoding given, using default character encoding ISO-8859-1
2009-08-05 04:54:22,478 [WebContainer : 4] DEBUG org.ajax4jsf.framework.renderer.AjaxPhaseListener - Process after phase RENDER_RESPONSE(6)
2009-08-05 04:54:22,478 [WebContainer : 4] DEBUG org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter - create HTML/XML parser for content type: application/pdf
2009-08-05 04:54:22,478 [WebContainer : 4] DEBUG org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter - Parser not have support for the such content type, send response as-is

Why does it say no content type given when I have explicitly set the content type ?
Has anybody faced this...??
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're trying to get a PDF straight from a JSF view, you're asking for trouble. JSF is expecting to output HTML. All you'll accomplish if you attempt to override the rendering process like that is frustration.

A more workable approach is to use a servlet or (non-JSF) JSP to render the PDF in the same way you would in a non-JSF application. Then put a URL reference to this servlet/JSP on your JSF view definition.

JSF isn't an exclusive platform. You can (and should) mix JSF and non-JSF request handlers when it makes sense to do so.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic