Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

[SOLVED] ADF 11G: opening PDF into new Window

djaziaNov 19 2009 — edited Apr 16 2010
Hello, I am using JDev 11.1.1.2.
I have a page into a bound Task FLow containing a pivot table and a "print "button".
I am using Jasper Report to create a PDF document.
I want this document to be opened into a new Window when the user click on the button.
I've been reading several threads/blogs to do this but it is not working.

Here the code of my button:
<af:commandButton text="Print"
id="cb1" useWindow="true"
action="#{viewScope.myBean.goReport}"
windowHeight="400" windowWidth="800"
immediate="true"/>

where viewScope.myBean.goReport returns "dialog:goReport"

Here the code I use to create my PDF:
// Create a PDF exporter
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(print, byteArrayOutputStream);
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ectx = context.getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
ServletOutputStream out = response.getOutputStream();
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Content-Disposition", "inline; filename=report.pdf");
response.setContentType("application/pdf");
// response.setContentLength((new Long(userInfoBean.getReportStream().length)).intValue());
out.write(byteArrayOutputStream.toByteArray());
out.flush();
out.close();
context.responseComplete();


Into my bounding task flow containing the page I have:
<view id="report">
<page>/report/report.jspx</page>
</view>

<from-activity-id>*</from-activity-id>
<control-flow-case id="__1">
<from-outcome id="__2">dialog:goReport</from-outcome>
<to-activity-id id="__3">report</to-activity-id>
</control-flow-case>

My report.jspx file i just a blank page attached to a backing bean:
<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=windows-1252"/>
<f:view>
<af:document id="d1" binding="#{backingBeanScope.backing_report_bean.d1}">
<af:form id="f1" binding="#{backingBeanScope.backing_report_bean.f1}"></af:form>
</af:document>
</f:view>
<!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_report_bean-->
</jsp:root>

I cannot get the PDF document to open into a new Window

If I put alone "dialog:goReport" into the button action attribut, I manage to have a blank page opened.
I I link "viewScope.myBean.goReport" method which is returning "dialog:goReport" and contains the PDF creation code to the button action I have the PDF document appearing but into the current window.
I tried putting also my PDF creation code into a launchListener, actionListener, returnListener but I still have my PDF document opening into the current window.

I am sure I am doing something wrong since it appears others have found a way to do it but I'm lost right now.
Can someone help me on this pls.

Jack
This post has been answered by Frank Nimphius-Oracle on Nov 20 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2010
Added on Nov 19 2009
11 comments
8,959 views