It is actually quite straightforward to render a PDF from a JSF
actionListener method in the backing bean:
public void pdfActionListener(final ActionEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
try {
Object response = context.getExternalContext().getResponse();
if (response instanceof HttpServletResponse) {
HttpServletResponse hsr = (HttpServletResponse)response;
hsr.setContentType("application/pdf");
//This methods uses iText to generate the pdf
writePdf(hsr.getOutputStream());
//Tell JSF to skip the remaining phases of the lifecycle
context.responseComplete();
}
catch (Exception e) {
...
}
}
You have the typical JSF problem however: the back button is not handled
very well, so if the user has the Adobe Acrobat plugin that shows the
pdf inside the browser, and he clicks the back button, he will see the
previous page, but the commandButtons and commandLinks won't do anything
the first time.
> >
> > Do you know of any jsf components to allow this, or better yet,
> > rendering of jsf result page directly to pdf (say in child window)?
>
There was a short discussion about the possibility of a pdf renderkit on
the myfaces mailing list a while ago, and we all agreed it would be a
nice project :) I don't think anyone started working on it yet though...
--
Jurgen Lust
Projectleader IT
Ghent University
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions