I needed a way to print content without showing it first. And it is a completely
different layout than the visible page and required data that was just entered on the
page.
I have this at the bottom of the visible page (Event.observe() is from Prototype):
<iframe id="printbox" name="printbox"
src="#{referralController.faxUrl}"
| width="0" height="0" style="border:none">
| </iframe>
|
| <script type="text/javascript">
| Event.observe(window, 'load', printFax);
| </script>
|
Here's the javascript function:
function printFax()
| {
| if (window.frames['printbox'].document.URL.indexOf("faxcover") !=
-1)
| {
| window.frames['printbox'].focus();
| window.frames['printbox'].print();
| }
| }
|
The function checks to see if the iframe contains any printable content by checking the
URL.
I leave the URL blank when first loading the page. When the print button is clicked the
backing bean method stores the data, sets the printing URL and then reloads the same page.
I include the conversation id so the printing page can find the data.
| faxUrl =
FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() +
| "/faxcover.seam?clr=true&cid=" + conversation.getId();
|
This works in both IE and FF. The page doesn't change visually but the print dialog
appears for the hidden layout.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4068404#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...