• Post Reply Bookmark Topic Watch Topic
  • New Topic

PDF USING JSF & FOP  RSS feed

 
sharad sonapeer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,


So,I am using JSF for the first time.I am able to produce the pdf using HTML & FOP but for my project I want it using JSF.

Basically I have done till I am able to call the backing bean function which is nothing but FOP class which responses back the PDF....

But the problem I am facing with JSF is that I can see the PDF generating on the server console but I can't get it streamed to the browser JSF page where I want to see the PDF ..(Basically PDF is generated using some other XML and XSL file using FOP program and then streamed to browser...and am doing this all on localhost) ....


But instead of loading the pdf am loading the same page where I clicked the getPDF....


I am using following bean function for the response...


public void renderXML(XSLTInputHandler input,
HttpServletResponse response) throws ServletException {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();

response.setContentType("application/pdf");

Driver driver = new Driver();
driver.setLogger(log);
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
driver.render(input.getParser(), input.getInputSource());

byte[] content = out.toByteArray();
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
} catch (Exception ex) {
throw new ServletException(ex);
}



Please anybody help me out....
This is DO OR DIE FOR ME TILL MONDAY....
 
Gabriel Claramunt
Ranch Hand
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use a plain old servlet redirected from your JSF screen
 
sharad sonapeer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks Gabriel for your response,

But I am not supposed to use servlets in my application...I have to convert my servlet into backing bean as the whole application is JSF only there is no room for servlets....that's why the problem has become severe....

Please can you suggest some other wayout..???
 
Gabriel Claramunt
Ranch Hand
Posts: 375
Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you allowed to put the code in a JSP?
like:
<%

response.write(xmlStream)

%>

?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if you can do that, you have to be extremely careful about it. The whitespace that makes no difference to HTML can damage a PDF so it's unreadable. That's why a servlet would be better. Perhaps whoever made the "no servlets" decision wasn't aware that the system was going to be asked to produce PDFs, so it might be worth trying to get that decision weakened slightly.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoever made the "no servlets" mandate doesn't understand the full power and flexibility of JSF. Part of that power is NOT having to use JSF for parts of the webapp that are better done in other ways. JSF is not an all-or-nothing solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!