views:

32

answers:

2

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
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
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
Hey Thanks man especially for the link ! Big help :)
Prabhat
You're welcome.
BalusC
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
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