Hi. I want create a pdf using iText. The method which does this is a JSF bean. What I want is, on click of a commandButton in JSF page, the PDF is created. It must then open as popup in a new window(or tab) keeping the JSF page unaltered. How can I accomplish this ? I know there is a way in javascript in which we can open a new window using window.open(), but then I want to access the list from JSF bean to create pdf. Thanks.
+1
A:
Add target="_blank"
attribute to the <h:form>
and it will submit into a new tab/window.
BalusC
2010-07-14 12:06:08
Thanks for your quick reply. Can you please explain ? When you give target="_blank", click on commandbutton, it calls the JSF bean and PDF gets created (in the form of Byte Array). How do I use this byte array to display (as outputStream)?
Prabhat
2010-07-14 12:11:23
I thought you already got that part working? To the point you just need to stream the bytes to the response body along with a correct set of headers. Anyway 4 years back I ever wrote a JSF oriented blog about this, it's still applicable: http://balusc.blogspot.com/2006/05/pdf-handling.html
BalusC
2010-07-14 12:19:32
Hey Thanks man especially for the link ! Big help :)
Prabhat
2010-07-14 12:32:48
You're welcome.
BalusC
2010-07-14 12:33:36
A:
You could replace the commandButton with a <a href="pathToPdfServlet" target="_blank">PDF</a>
, which is mapped to a servlet. This servlet would set the response content type to application/pdf
, call iText and write PDF to the output stream.
Witek
2010-07-14 12:12:45
Thanks for your quick reply. However, I get two problems with this approach.1. It has to be commandButton (requirement)2. How to access JSF bean data in servlet ?
Prabhat
2010-07-14 12:14:49