Popup Windows Javaserver faces.

I wanted to build a popup window that I could use to bring up a print dialog in a web page. It’s no use using the JAVA print dialog because it would appear on the web server.

So:-

FORM WITH DATA —> CLICK PRINT —> Bring up Popup Print Window —> CLOSE WINDOW –> RETURN TO FORM

The Popup JSF page

1. Create the Popup window java server faces page. (just a normal jsf page)
2. Add a Button to the page to close it
3. Add a static text box, rename it to txtJAVASCRIPT, set the escape checkbox to off, add a binding attribute
4. Now, on the Popup I have a close button and the code in the close button simply sets the static text box’s javascript:

Ofcourse you can change the settings as you wish (i.e. popup window size)

3. Making the popup appear.

a. Add a static text box, rename it to txtJAVASCRIPT, set the escape checkbox to off, add a binding attribute (this stores the javascript when i want the box to appear).

b. Add a button to the form you want the popup to appear on, in the button java put :-

public String cmdPRINT_action() {
// in this case i am printing a report so i set the session variable to tell the server the popup needs to be displayed
getSessionBean1().sPrintReportRequest="rptzones";
// now set the txt of the static text box I set up on the same page, note its normally not visible or rendered
// in this case the popup is a jsf page called frmPRINTREPORTS.jsp
txtJAVASCRIPT.setRendered(true);
txtJAVASCRIPT.setText("<script language='javascript'>popUp('frmPRINTREPORTS.jsp');</script>" );
txtJAVASCRIPT.setVisible(true);
return null;
}

4. Lastly in the form that called the popup I want to stop it from appearing so I have to kill the javascript.