0% found this document useful (0 votes)
360 views32 pages

Using Jasper Report in ADF Application (Step-by-Step)

This document provides step-by-step instructions for using Jasper Reports in an Oracle Application Development Framework (ADF) application. It explains how to connect an ADF application to a database, design a report using iReport, and call the report from the ADF application to print selected employee data. The key steps are: 1) Install and set up iReport to design reports; 2) Create an ADF application and connect it to the database; 3) Design a report in iReport to display employee data; 4) Call the report from the ADF application to print data for a selected employee.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
360 views32 pages

Using Jasper Report in ADF Application (Step-by-Step)

This document provides step-by-step instructions for using Jasper Reports in an Oracle Application Development Framework (ADF) application. It explains how to connect an ADF application to a database, design a report using iReport, and call the report from the ADF application to print selected employee data. The key steps are: 1) Install and set up iReport to design reports; 2) Create an ADF application and connect it to the database; 3) Design a report in iReport to display employee data; 4) Call the report from the ADF application to print data for a selected employee.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

More Next Blog» [email protected] Dashboard Sign Out

Sameh Nassar
This blog is concerned with the ADF/BPM technology provided by Oracle. I Hope this blog helps fellow
Oracle ADF/BPM Developers

Sunday, December 9, 2012

Using Jasper Report In ADF Application (Step-by-Step) About Me

In my previous post http://sameh- Sameh Nassar


nassar.blogspot.com/2009/10/using-jasper-reports-with- Mitchelstown, C ork,
jdeveloper.html I explain how to use Jasper Report but because of Ireland
many people send me many requests for explain this topic in more
detail so I will explain it in step by step.
I am Senior Oracle ADF Developer, I am
one of the development team works in
our example will make application with one screen this screen has
C ore Software C ompany located in
a table of employees you should select an employee and send the Mitchelstown - Ireland
selected employee id to jasper report to print the selected http://www.coresoftware.ie
employee data. E:[email protected]
View my complete profile
Before we begin be sure of:

1- You download iReport-4.0.1 (you can get it from Blog Archive


http://sourceforge.net/projects/ireport/files/iReport/iReport-
► 2016 (3)
4.0.1/) I download iReport-4.0.1-windows-installer.exe.
► 2015 (18)
► 2014 (7)
2- You have database has hr schema.
► 2013 (1)
▼ 2012 (3)
3- Setup JDeveloper 11g (any release).
▼ December (1)
Using Jasper Report In ADF
Now we can begin ...... Application (Step-by-St...
► May (1)
Step 1: ► March (1)
► 2010 (6)
Setup iReport-4.0.1 ► 2009 (14)

Followers

Followers (68) Next

Step 2: Follow
Open JDeveloper and make new ADF Application (name it for
example JasperApplication)

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 1/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

FEEDJIT Live Traffic Feed

Visitors

2,103 Pageviews
Apr. 05th - May. 05th

Popular Posts

JavaScript With ADF Faces


Samples
In your ADF web
application you may want
to use javaScript functions
to perform some actions in
client side. I will list some of the major ...

Using Jasper Report In ADF


Application (Step-by-Step)
In my previous post
http://sameh-
nassar.blogspot.com/2009/
10/using-jasper-reports-
with-jdeveloper.html I explain how to use
Jasper Repor...
Step 3:
Use C heckbox For
Selecting Multiple Rows
Connect your application to your database HR Schema by right From af:table
click in your Model application ---> new ---> ADF Business One of the feature which
Components ---> Business Components From Table existed in JDeveloper 10g
but not found in
JDeveloper 11g is using checkbox for
selecting multiple rows from af:ta...

C reate PL/SQL Function


And C all It From Your ADF
Application
In many situations you
need to create PL/SQL
function in your database
and call it from your application. This
post will illustrate how to c...

Using Jasper Reports In ADF Applications


You can check this for step by step
calling jasper report http://sameh-
Add your connection and test the connection nassar.blogspot.ie/2012/12/using-jasper-
report-in-adf-application...

Getting the Value from a


SelectOneC hoice List (Not
Index)
One of the Issue I found
when I use
af:selectOneC hoice
component that when I want to get the

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 2/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
selected value from one of the
selectOneC hoice ...

C all Oracle Reports From


Your ADF Application
One of the main issues that
can face oracle ADF
Developers is calling oracle
reports. This post will
illustrate step by step how to call o...

Dealing With Dates in Java


Many developers sometimes face a
problems when they dealing with dates.
In java there are many types of dates
as: - java.util.Date - jav...

Apply MDS To Oracle ADF


Application
What is MDS? Metadata
Services (MDS) is a
Add one Entity Objects (Employees) feature provided by oracle
to store customization and
personalization information in a
repositor...

C all Oracle Reports From


Your ADF Application (Hide
Report Parameters From
URL)
Hello ADF Developers, In
my previous post
http://sameh-
nassar.blogspot.com/2010/07/call-oracle-
reports-from-your-adf.html I explain
a wa...
Add one Updatable View Objects

Total Pageviews

Then press finish, your application should be like this

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 3/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Step 4:
Create new jspx page (name it for example employees.jspx)
In your ViewController project right click on Web Content folder
then new --->JSF ---> JSF Page

From the Data Controls drag EmployeesView1 to your page as an


ADF Read-only Table

From Row Selection Select Single Row

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 4/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Add a button above a table (text it for example Run Report) and
its action point to a method in a back bean (for example Back
bean name is JasperBean.java)

To get the selected employee id:


DCIteratorBinding empIter = (DCIteratorBinding)
getBindings().get("EmployeesView1Iterator");
String empId =
empIter.getCurrentRow().getAttribute("EmployeeId").toString();

where EmployeesView1Iterator is the iterator name in the page


definition and EmployeeId is the attribute name in the
EmployeesView.

now we should pass the selected employee Id to jasper report so,


you should make a map and set the parameter like
Map m = new HashMap();
m.put("employeeId", empId);// employeeId is a jasper
parameter name

then you should call the jasper report like this method
runReport("empReport.jasper", m);

where runReport is the method take jasper report name


(empReport.jasper) and the map which hold the parameter

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 5/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
write this code in your JasperBean.java

---------------------------------------------------------------
-----------------------------------------------

1 public BindingContainer getBindings()


2 {
3 return BindingContext.getCurrent().getCurrentBindings
4 }
5
6 public Connection getDataSourceConnection(String dataSou
7 {
8 Context ctx = new InitialContext();
9 DataSource ds = (DataSource)ctx.lookup(dataSourceNam
10 return ds.getConnection();
11 }
12
13 private Connection getConnection() throws Exception
14 {
15 return getDataSourceConnection("hrDS");// use datasou
16 }
17
18 public ServletContext getContext()
19 {
20 return (ServletContext)getFacesContext().getExternalCo
21 }
22
23 public HttpServletResponse getResponse()
24 {
25 return (HttpServletResponse)getFacesContext().getExte
26 }
27
28 public static FacesContext getFacesContext()
29 {
30 return FacesContext.getCurrentInstance();
31 }
32
33 public void runReport(String repPath, java.util.Map para
34 {
35 Connection conn = null;
36 try
37 {
38 HttpServletResponse response = getResponse();
39 ServletOutputStream out = response.getOutputStream(
40 response.setHeader("Cache-Control", "max-age=0");
41 response.setContentType("application/pdf");
42 ServletContext context = getContext();
43 InputStream fs = context.getResourceAsStream("/repo
44 JasperReport template = (JasperReport) JRLoader.load
45 template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_S
46 conn = getConnection();

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 6/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
47 JasperPrint print = JasperFillManager.fillReport(tem
48 ByteArrayOutputStream baos = new ByteArrayOutputStre
49 JasperExportManager.exportReportToPdfStream(print, b
50 out.write(baos.toByteArray());
51 out.flush();
52 out.close();
53 FacesContext.getCurrentInstance().responseComplete(
54 }
55 catch (Exception jex)
56 {
57 jex.printStackTrace();
58 }
59 finally
60 {
61 close(conn);
62 }
63 }
64
65 public void close(Connection con)
66 {
67 if (con != null)
68 {
69 try
70 {
71 con.close();
72 }
73 catch (Exception e)
74 {
75 }
76 }
77 }

JasperBean.java hosted with ❤ by GitHub view raw

---------------------------------------------------------------
-----------------------------------------

After you write this code you will find Jasper library missing

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 7/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

to get jasper libraries goto the folder which you setup iReport for
example in this path
C:\Program Files (x86)\Jaspersoft\iReport-
4.0.1\ireport\modules\ext
and get these libraries:
1- iText-2.1.7.jar
2- jasperreports-4.0.1.jar
3- jasperreports-fonts-4.0.1.jar

add this libraries to your ViewController project ---> Right click on


the project ---> Project Properties--->Libraries And Classpath ---
> Add JAR/Directory

Now your code should have no error

Now my Back bean code is :


---------------------------------------------------------------
-------------------------------------------------------

1 import java.io.ByteArrayOutputStream;
2 import java.io.InputStream;
3 import java.sql.Connection;
4 import java.util.HashMap;
5 import java.util.Map;
6 import javax.faces.context.FacesContext;
7 import javax.naming.Context;
8 import javax.naming.InitialContext;
9 import javax.servlet.ServletContext;

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 8/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
10 import javax.servlet.ServletOutputStream;
11 import javax.servlet.http.HttpServletResponse;
12 import javax.sql.DataSource;
13 import net.sf.jasperreports.engine.JasperExportManager;
14 import net.sf.jasperreports.engine.JasperFillManager;
15 import net.sf.jasperreports.engine.JasperPrint;
16 import net.sf.jasperreports.engine.JasperReport;
17 import net.sf.jasperreports.engine.type.WhenNoDataTypeEnu
18 import net.sf.jasperreports.engine.util.JRLoader;
19 import oracle.adf.model.BindingContext;
20 import oracle.adf.model.binding.DCIteratorBinding;
21 import oracle.binding.BindingContainer;
22
23 public class JasperBean
24 {
25 public JasperBean()
26 {
27 }
28
29 public String runReportAction()
30 {
31 DCIteratorBinding empIter = (DCIteratorBinding) getB
32 String empId = empIter.getCurrentRow().getAttribute(
33 Map m = new HashMap();
34 m.put("employeeId", empId);// where employeeId is a j
35 try
36 {
37 runReport("empReport.jasper", m);
38 }
39 catch (Exception e)
40 {
41 }
42 return null;
43 }
44
45 public BindingContainer getBindings()
46 {
47 return BindingContext.getCurrent().getCurrentBinding
48 }
49
50 public Connection getDataSourceConnection(String dataSo
51 throws Exception
52 {
53 Context ctx = new InitialContext();
54 DataSource ds = (DataSource)ctx.lookup(dataSourceNa
55 return ds.getConnection();
56 }
57
58 private Connection getConnection() throws Exception
59 {
60 return getDataSourceConnection("hrDS");// datasource

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 9/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
61 }
62
63 public ServletContext getContext()
64 {
65 return (ServletContext)getFacesContext().getExterna
66 }
67 public HttpServletResponse getResponse()
68 {
69 return (HttpServletResponse)getFacesContext().getEx
70 }
71 public static FacesContext getFacesContext()
72 {
73 return FacesContext.getCurrentInstance();
74 }
75 public void runReport(String repPath, java.util.Map pa
76 {
77 Connection conn = null;
78 try
79 {
80 HttpServletResponse response = getResponse();
81 ServletOutputStream out = response.getOutputStream
82 response.setHeader("Cache-Control", "max-age=0");
83 response.setContentType("application/pdf");
84 ServletContext context = getContext();
85 InputStream fs = context.getResourceAsStream("/repo
86 JasperReport template = (JasperReport) JRLoader.loa
87 template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_S
88 conn = getConnection();
89 JasperPrint print = JasperFillManager.fillReport(te
90 ByteArrayOutputStream baos = new ByteArrayOutputSt
91 JasperExportManager.exportReportToPdfStream(print,
92 out.write(baos.toByteArray());
93 out.flush();
94 out.close();
95 FacesContext.getCurrentInstance().responseComplete
96 }
97 catch (Exception jex)
98 {
99 jex.printStackTrace();
100 }
101 finally
102 {
103 close(conn);
104 }
105 }
106
107 public void close(Connection con)
108 {
109 if (con != null)
110 {
111 try
http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 10/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

112 {
113 con.close();
114 }
115 catch (Exception e)
116 {
117 }
118 }
119 }
120 }

JasperBean.java hosted with ❤ by GitHub view raw

---------------------------------------------------------------
-----------------------------------------------------------
Now depending on my previous code we should make a report the
name of this report should be "empReport" and has one parameter
"employeeId"

Step 5:

Open iReport and make a connection to hr database but first .....


iReport has not oracle database driver so you use oracle database
you should first add a ojdbc jar file to the classpath of iReport.

you can get ojdbc jar file in your middleware home like:
C:\Oracle\Middleware\wlserver_10.3\server\lib and search for
ojdbc6.jar

In iReport goto Tools---> Options ---> Classpath and add


ojdbc6.jar

Now make a new connection to hr schema

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 11/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Now from File ---> New and make new Report

Choose any template or make it blank then press "Launch Report


Wizard"

Write report name "empReport" and under your web content folder
in ViewController project make new folder "reports" and save the
report on this path

Press on Design query button and select your schema then drag
Employees table

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 12/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

then press Ok you will find the report query will generated then
press Next and shuttle the field you want to displayed in your
report

Then press next then finish. You will find you report generated.
Goto the report query as shown:

and make new Parameter "employeeId"

add where clause to the query like:


WHERE EMPLOYEES."EMPLOYEE_ID"=to_number($P{employeeId})

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 13/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Now you can preview your report by pressing on "Preview" button


and enter for example employeeId = 200

Now compile your report to generate .jasper file in your application

If you goto your application you should something like this:

before you run be sure of two things:


1- any picture you use in jasper should be in the class path

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 14/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

2- You should define datasource in your weblogic "as we write in


the code datasource is hrDS"

for how you can define data source in weblogic try this
http://www.mediafire.com/view/?g7odbc06rpad1aa

Step 6:
run your application and select any employee then press on "Run
Report" button

for example select employee Id= 104 then run report

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 15/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

you can download the application from this link JasperApplication

To open the report in new window:

1- In the .jspx right click on the af:document -->Facets - Document --> Meta
Container
2- Inside f:facet - metaContainer add af:resource with type="javascript" as:

1 <f:facet name="metaContainer">
2 <af:resource type="javascript">
3
4 </af:resource>
5 </f:facet>

meta.xml hosted with ❤ by GitHub view raw

inside af:resource you can add javascript function

function newWindow()
{
document.getElementById("f1").target = "_blank;targetfeatures=toolbar=no
location=no directories=no menubar=no";
}

where "f1" is the af:form id.

So the structure will be:

1 <f:facet name="metaContainer">
2 <af:resource type="javascript">
3 function newWindow()
4 {
5 document.getElementById("f1").target = "_bla
6 }
7 </af:resource>
8 </f:facet>

js.xml hosted with ❤ by GitHub view raw

To call this function add button or link and inside this link add clientLister as:

1 <af:commandLink text="Run Report" id="cl1">


2 <af:clientListener method="newWindow" type="act
3 </af:commandLink>

call.xml hosted with ❤ by GitHub view raw

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 16/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Posted by Sameh Nassar at 3:27 PM


Reactions: funny (0) interesting (3) cool (5)

83 comments:

Muhammad Nasir December 9, 2012 at 8:18 PM

Very Nice and easy to understand. thanks for sharing such a nice
content.

Reply

Replies

Sameh Nassar December 10, 2012 at 12:00 PM

Thanks Muhammad you are welcome.

Reply

MinBzid December 17, 2012 at 11:22 PM

Perfect explanation

Reply

mhawad January 1, 2013 at 5:01 AM

‫ھذا ھو اﻹﺑداع اﻟﺣﻘﯾﻘﻲ ﻓﻲ ﻋرض اﻟﻣﻌﻠوﻣﺔ‬


‫ﺟزاك ﷲ ﻋﻧﺎ ﻛل ﺧﯾر‬

Reply

Replies

Sameh Nassar January 2, 2013 at 2:02 AM

‫ﺷﻛرا ﻟك‬

Reply

Rashid January 3, 2013 at 11:34 PM

Brother Sameh,

can you please tell me that I want to develop an Oracle based large
scale web application and want to use some reporting it it. Jasper
reporting tool is appropriate for the said reporting? I mean, the
features grouping, controls etc (like we use in .Net C rystal Report)
are available?

Please reply me here(or if you can personally in my address


[email protected])

Jazak ALLAH

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 17/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
Reply

Replies

Sameh Nassar January 5, 2013 at 3:26 AM

Hi Rashid,

I don't work with C rystal Report before but Jasper has


grouping, controls, graphs, calling java methods feature
and sub-report. We make very large scale applications
with complex report using jasper.

Regards,

Reply

Anonymous February 5, 2013 at 12:40 PM

The Report Integration Framework goes far beyond this:


http://whitemagicsoftware.com/software/java/rif/

Read C hapter 15 (free) to see a generic way to integrate


JasperReports with ADF:
http://whitemagicsoftware.com/books/indispensable/

The idea is that you can decouple any report framework from the
ADF application. The last thing you want to do is couple Oracle
Reports, JasperReports, BIRT, or C rystalReports to your application
when you don’t need to.

The Report Integration Framework provides a pluggable system


where you can swap out one report engine for another, and not one
line of code in the ADF application needs to change.

Reply

sief February 6, 2013 at 6:18 PM

Dear eng.sameh
I Follow the steps but the program generate this error
javax.naming.NameNotFoundException: Unable to resolve 'hrDS'.
Resolved ''; remaining name 'hrDS'
please if u can fixed this issue i'll appreciate

regards

Reply

Replies

Sameh Nassar February 8, 2013 at 2:31 AM

Dear sief,
this is not an issue, you should define data source in your
weblogic with JNDI name hrDS.
If you run your application in jdeveloper so you should
define data source in integrated weblogic. you can
connect to the weblogic console
like(http://localhost:7101/console) and enter weblogic
username and password like(weblogic/weblogic1) and
from services menu define generic data sourse with name
hrDS.

Regards

Reply

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 18/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Nasir Amin February 20, 2013 at 8:26 AM

Wao great link and perfect guidelines :) @Samah Nassar sir, I have
done it completely it works very well ... but I also tried to generate
the jasper report by a view which is based of the Parametrized view
but it is not working there ....Any suggestion please ?

Reply

Replies

Sameh Nassar February 20, 2013 at 5:06 PM

Hi,
I do understanding what is the meaning of generate the
jasper report by a view??

Jasper report should hold the query internally this view


may has a parameter and you can pass this parameter as
I explain in this example.
Regards

Reply

Daniel Torres February 21, 2013 at 8:34 AM

Hi,
C an you help me?
I've trying to generate reports with jasper report but i have this
error:
C aused by: java.lang.NoC lassDefFoundError:
net/sf/jasperreports/engine/util/JRLoader
at beans.JasperBean.runReport(JasperBean.java:88)

The code line is:


JasperReport template = (JasperReport) JRLoader.loadObject(fs);

In the runReport method

Any help?
Thanks.

Reply

Replies

Sameh Nassar February 21, 2013 at 2:08 PM

Hi
C heck the version of ireport which you are use and the
libraries you use in your application. Try to use the same
version of ireport and the libraries in my example.
Regards

Reply

Rahul Sharma March 5, 2013 at 11:25 PM

Hi Samesh Sir,

Please help me with this step.

2- You should define datasource in your weblogic "as we write in the


code datasource is hrDS"

C an you upload a step-by-step tutorial for this step?

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 19/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
Thank you in advance,

Rahul

Reply

Replies

Sameh Nassar March 6, 2013 at 3:32 AM

Hi Rahul,

I make small documentation for how you can define data


source in weblogic you can download it from
http://www.mediafire.com/view/?g7odbc06rpad1aa

Regards,

Reply

Ali March 7, 2013 at 1:33 PM

Hi Sameh,
Is it possible to download the pdf to the users OS (maybe using
fileDownloadActionListener) as a file or open the pdf in a new
browser tab or window and keep the current view of the jspx page?

Thank you for this useful tutorial.

Reply

Replies

Sameh Nassar March 8, 2013 at 3:55 AM

Hi Ali ,
You don't need to use fileDownloadActionListener you can
insert inside button which will run the report
af:clientListener which call javascript method to open the
report in new window like:

af:commandButton text="Run Report" id="cb1" action="#


{jasper.runReportAction}">
af:clientListener type="action" method="newWindow"/>
/af:commandButton>

and in your jsp page and this javascript method:


function newWindow()
{
document.getElementById("f1").target =
"_blank;targetfeatures=toolbar=no location=no
directories=no menubar=no";
}

Malek Tayyeb August 31, 2013 at 11:50 PM

hey Sameh , hope to get replay on my question here ?


I wanted to open Jasper Report as PDF on new web
browser window , so I did your solution above , it works
fine , but! the command button turned into disabled after
click it , i am sure i am using your servlet , your work
around for new Window , do you have any idea ??

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 20/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
sara April 27, 2014 at 12:42 AM

Hi Sameh
I need to open pdf report in new window too.
But i could not use your solution .
May you explain me more ?
1- where can i write function newWindow() and how ?
2- what is "f1" in this line
document.getElementById("f1").target ?

thanks a lot

Sameh Nassar April 27, 2014 at 3:59 AM

Hi Sara,
1- in your .jspx after af:document you can add
af:resource with type = javascript and inside af:resource
you can add javascriptmethod like this:

function newWindow()
{
document.getElementById("f1").target =
"_blank;targetfeatures=toolbar=no location=no
directories=no menubar=no";
}

2- "f1" is the id of af:form like:

Reply

betty March 27, 2013 at 8:07 AM

HiSameh,
Thank you so much for your clear explanation:)

Ellerine sağlık ;)
Betül

Reply

adf learner April 5, 2013 at 3:50 AM

Thank you so much...Nicely explained.


one question. I implemented the open in new window functionality
and it is working. but one problem is if one report is opened in a
window and without closing it, if I select another employee and
generate report, then it gives error. the error is shown in the same
window where the first report was shown. Error is "Error 403--
Forbidden
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.4 403 Forbidden
The server understood the request, but is refusing to fulfill it.
Authorization will not help and the request SHOULD NOT be
repeated. If the request method was not HEAD and the server
wishes to make public why the request has not been fulfilled, it
SHOULD describe the reason for the refusal in the entity. This status
code is commonly used when the server does not wish to reveal
exactly why the request has been refused, or when no other
response is applicable."

Reply

Replies

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 21/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Sameh Nassar April 6, 2013 at 11:56 AM

Hi,
I try your scenario put it work without error. You can send
your code in my email to check it.

Regards,

Reply

Saurabh May 9, 2013 at 11:43 PM

Hi,
I tried it. But the program is not running as I am clicking on the
print button I haven't got any response fro it. I follow all the steps
and i am not getting any error also. C an you help me for it.

Regards
Saurabh

Reply

Replies

Sameh Nassar May 10, 2013 at 6:28 AM

Hi,

Are you download my application and it is not running?


are you sure that you make data source in weblogic?

abc January 19, 2014 at 11:37 PM

same here...after click on button m not getting any error


or report....but in j developer there is null point exception
in jasper loader

Reply

Anonymous June 30, 2013 at 5:21 AM

Hi,

Thank you for such a nice example.


I just want to know.How I can put my whole table data using this
example.

Kindly reply ASAP


Thanks in advance

Reply

Replies

Sameh Nassar July 2, 2013 at 11:12 AM

Hi,
What do you mean with whole table? do you mean you
want to display all rows of employees in table? if that you
can send no parameters and in the jasper report query
remove the where clause it will display all rows.

Regards,

Reply

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 22/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Ahmad Khoshnaw July 27, 2013 at 2:28 AM

‫ﺟزاك ﷲ اﻟف ﺧﯾر اﺑداع ﻓﻲ اﻟﺷرح واﺳﻠوب اﻟﻌرض وﻓﻘك ﷲ ﻟﻣﺎ ﯾﺣﺑﮫ وﯾرﺿﺎه‬

Reply

Replies

Sameh Nassar July 27, 2013 at 4:59 PM

‫ﺷﻛرا ﻟك‬

Reply

Anonymous September 10, 2013 at 4:07 AM

excellent publish, very informative. I wonder why the opposite


specialists of this
sector do not understand this. You must continue
your writing. I'm confident, you have a huge readers' base
already!

Look at my web page ... appetite women experience

Reply

Replies

Sameh Nassar September 10, 2013 at 1:30 PM

Thank You...

Reply

Alaa Kamal October 8, 2013 at 5:46 PM

hi haw are you thx you for your very good work may i ask you
about using .rdf report
i want adf application example in more details about Using oracle
Report (.rdf) In ADF Applicationoracle

Reply

Replies

Sameh Nassar October 9, 2013 at 1:47 AM

Hi,

you can call oracle report from your ADF Application as I


post in http://sameh-nassar.blogspot.com/2012/05/call-
oracle-reports-from-your-adf.html

Reply

Mahmoud Yacine November 7, 2013 at 2:44 AM

‫ ﻟذﻟك ﺗﺳﺗطﯾﻊ اﯾﺻﺎل‬.‫ﻣﺎﯾﻣﯾزك ﻋن اﻟﻘﯾﺔ أﻧك ﺗﺷرح ﺑﺎﻟﺗﻔﺻﯾل وﺗذﻛر ﻛل ﺷﻲء ﺣﺗﻰ اﻟﺗﻔﺎﺻﯾل اﻟﺑدﯾﮭﯾﺔ‬
‫اﻟﻣﻌﻠوﻣﺔ ﻟﻠﻘﺎرء ﺑﺷﻛل ﺳﻠس‬.

‫ﺷﻛرا ﻟك‬.

Reply

golriz nourani December 4, 2013 at 12:37 AM

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 23/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
Hi Sameh
I have arabic word (field of query) in my report I can see them in
report of ireport but when I run my application , the arabic words
aren't shown in pdf on browser .
shall you help me?
regards

Reply

Replies

Sameh Nassar December 5, 2013 at 1:13 PM

Hi,
Arabic words will not appear if you use fonts from
IReport. you sould use arial.ttf font, From IReport you can
make font as a jar file hold arial.ttf file and add this jar
file in the IReport (If you do not know how to make this
jar file I made a jar file you can download this jar file
from
http://www.mediafire.com/download/48m0ihpazqaihz7/JF
onts.jar and add this jar file in the IReport classpath) now
select any field from the report (that will display arabic
word) and from property change the font to "sdArial"
where sdArial is the name that defined inside my jar file

golriz nourani December 6, 2013 at 10:06 PM

Dear Sameh
Thanks a lot , it works.

Reply

Alaa Kamal December 5, 2013 at 7:09 PM

Thx you I will try Ariel jar and I will told you the result just I want
thx you aging for your effort

Reply

Replies

Sameh Nassar March 29, 2014 at 7:48 AM

Thanks

Reply

vikalp jain March 28, 2014 at 11:51 AM

very nice...quite informative..!!!!..keep posting like this blog..!!!!

Reply

Replies

Sameh Nassar March 29, 2014 at 7:49 AM

Thanks

Reply

Anonymous April 7, 2014 at 6:08 AM

Thank you for this tutorial.


For set up all things to work for me i had to change two things.

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 24/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

1. getC onnection - there is no need to define data JNDI source on


WLS.

private C onnection getC onnection() throws Exception


{
// return getDataSourceC onnection("hrDS");// use datasourse in
your application

String amDef = "he.model.AppModule";


String config = "AppModuleLocal";
PreparedStatement st = null;

AppModuleImpl am =(AppModuleImpl)
C onfiguration.createRootApplicationModule(amDef,config);
st = am.getDBTransaction().createPreparedStatement("select 1
from dual", 0);
C onnection conn = st.getC onnection();
return conn;
}

2. add some aditional libraries


- groovy_all.... jar
- jcommon ... jar

Reply

Anonymous April 27, 2014 at 11:17 PM

Hi Sameh :
what do i write in ireport for any images in ireport evevn it workd?
I write "my_img.jpg" but in adf it has error .

Reply

shahid hafeez April 29, 2014 at 10:49 PM

Dear Nasar, Aslam u Alakum,


I have followed all the process as you told. Bur find the following
error kindly help me.

Error 500--Internal Server Error

java.lang.IllegalStateException: strict servlet API: cannot call


getWriter() after getOutputStream()
at
weblogic.servlet.internal.ServletResponseImpl.getWriter(ServletRes
ponseImpl.java:307)
at
javax.servlet.ServletResponseWrapper.getWriter(ServletResponseW
rapper.java:122)
at
com.sun.faces.context.ExternalC ontextImpl.getResponseOutputWrit
er(ExternalC ontextImpl.java:723)
at
javax.faces.context.ExternalC ontextWrapper.getResponseOutputWri
ter(ExternalC ontextWrapper.java:669)
at
javax.faces.context.ExternalC ontextWrapper.getResponseOutputWri
ter(ExternalC ontextWrapper.java:669)

Reply

Replies

Sameh Nassar April 30, 2014 at 2:01 AM

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 25/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
Wealekom Aslam,

you can check the version of IReport and JDeveloper


which you are use because sometime the version of the
library cause errors. try to use IReport any of version 4

Ahmed March 1, 2017 at 7:01 AM

Dear Sameh and shahid,


We can solve this issue without back to old versions of
Jasper by modifing the properties of given report to
choose from drag box 'Java' instead of 'Groovy' in
language property

Sameh Nassar March 5, 2017 at 4:00 AM

Thanks Ahmed :)

Reply

lage raho June 6, 2014 at 12:30 AM

Hi Sameh,

Thanks for nice article, It was really helpful to get started with basic
of Jasper and its integration with ADF. I've followed the demo
application and it works perfectly fine for me.

However when I implemented the same thing in my application it


works for first time only. I mean when I click on button to download
reports, it works fine. But then it gives the Processing cursor when I
bring mouse on the button.

Any help would be greatly appreciated.

Thanks

Reply

shahid hafeez July 18, 2014 at 10:03 PM

Dear Sameh,

Aslam u Alakum,

Thanks for this wonderful post.

When use new window code in adf page for report . The calling
button disabled . C an u please help me

Reply

Replies

Sameh Nassar July 22, 2014 at 2:26 AM

Hi,
you can use af:commandLink with styleC lass="x7j
p_AFTextOnly" instead of af:commandButton

Reply

kapil singh March 18, 2015 at 7:44 AM

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 26/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
Hello Sameh,
Although it has been over 2 years since you originally posted this
article, it has helped me tremendously. Thank you for taking the
time to write this post, and also answer the questions posted by
others.

Reply

Replies

Sameh Nassar March 25, 2015 at 2:47 AM

Thank You...

Reply

Farrukhjamal May 10, 2015 at 10:01 PM

hi samesh

I followed your post and got succeeded with calling single report
from application but when i call a report that has sub reports in it it
gives me the error.
I am using J developer 12 with

Reply

Replies

Jamal Shaaban February 16, 2016 at 6:09 AM

Hi ,

I faced the same problem and i solved it by using this


lines

File reportFile = new File(context.getRealPath("/reports/"


+ repPath));
conn = getC onnection();
JasperPrint print =
JasperFillManager.fillReport(reportFile.getAbsolutePath(),
param, conn);
JasperExportManager.exportReportToPdfStream(print,
response.getOutputStream());

Sameh Nassar February 16, 2016 at 7:42 AM

Thanks Jamal.

Reply

SHAN September 16, 2015 at 12:30 AM

Hi sameh
Thank you so much for your clear explanation
my question

How can I use following js function inside .jsff page fragment part of
taskflow which is rendered as region in jsf page.because there is no
af:form in the fragment.

function newWindow()
{
document.getElementById("f1").target =
"_blank;targetfeatures=toolbar=no location=no directories=no
menubar=no";

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 27/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
}

Reply

Replies

Sameh Nassar September 17, 2015 at 2:11 PM

SHAN,

Try to add this java script in the .jsf page or in the page
template

Reply

Yazan Mohammad November 26, 2015 at 12:03 AM

Dear Sameh,

First of all thank you for the nice post.

Well, I have a question regarding this post is can I select more than
one employee and display their data in table.

Thank you very much!

Best Regards,

Reply

Replies

Sameh Nassar November 26, 2015 at 6:34 AM

Hi,
Yes you can. Simply you can select multiple rows from
the table and create string as String where= emp_id in
(10,20,40); (where 10, 20, 40 is the selected employees
id) and send this where as a parameter to the jasper
report.
For how to get selected rows you can check this
http://sameh-nassar.blogspot.ie/2009/12/use-checkbox-
for-selecting-multiple.html

or

https://blogs.oracle.com/aramamoo/entry/getting_all_sel
ected_rows_in_adf_table_with_multiple_rows_selection_e
nabled

Reply

Yazan Mohammad November 29, 2015 at 3:34 AM

Thank you very much Sameh!!

Your help appreciated!

Reply

emad muse January 4, 2016 at 7:33 AM

Thank you very much Eng-Sameh


But I have a problem
This message appears

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 28/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Error 500--Internal Server Error


From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.5.1 500 Internal Server Error

The server encountered an unexpected condition which prevented it


from fulfilling the request.

Reply

Replies

Sameh Nassar January 4, 2016 at 7:52 AM

C heck the server log and see what is the exception, this
error is generic you should see the server log to know
where this exception happen.

Reply

adf challenger January 31, 2016 at 4:45 AM

Thank you very much Sameh


But I have a question
if i want to deploy this application remotely ny ear file what needed

Reply

Atif Aslam February 15, 2016 at 3:16 AM

Dear Sameh,

Thanks for the post it's really helpful.


My code is stuck on one one thing when i am using commandbutton
it works and i can see the report but when i use button as
commandbutton is deprecated clicking Run Report just refreshes the
page i don't get any error messages although i can see in the code
that pdf is generated but not sure why its not displayed and what
should i do if i would like to use button in place of commandbutton.

Thanks

Reply

Replies

Sameh Nassar February 16, 2016 at 4:50 AM

Try to set button partialSubmit="false"

Reply

Unknown May 23, 2016 at 1:10 AM

hi samesh i tried this application, but when i am click the button


"Run Report" it is in same page only. Please can u help me.

After deploying my log file looks like..


Target URL -- http://127.0.0.1:7101/JasperReport-ViewC ontroller-
context-root/faces/employees.jsf

Reply

Replies

Sameh Nassar May 24, 2016 at 6:09 AM

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 29/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
What do you mean by, it is in same page only? do you
mean the page is refreshed and no report opened? If yes,
is there any error on the server log? If no, try to set "Run
Report" button partialSubmit="false" and see

K. SANTHOSH odc May 29, 2016 at 10:37 PM

I set partialsubmit="false", yet i am facing the same


problem

Anonymous June 30, 2016 at 2:37 AM

Did you resolv the problem?


i have the same, please Help!

Sameh Nassar July 4, 2016 at 1:16 AM

If you use region (.jsff) page this way will not work you
have to use servlet to call the report. You can have a look
on this

https://community.oracle.com/thread/3689943?tstart=0

Reply

drasko June 8, 2016 at 1:39 AM

Sameh greeting and,


I acted according to the instructions of your blog "Using Jasper
Report In ADF Application (Step-by-Step)", but when you do
everything right when I select any record from the table that opens
and press the Run button repot, not otavra is no report nor shows
no error. Please if you have any idea where it might be a mistake to
me pomogmen.
Greetings
Drasko
My email: [email protected]

Reply

Replies

Sameh Nassar June 8, 2016 at 2:50 PM

Do you run the report from page fragment (.jsff)? if yes,


you have to use servlet to run the report. you can check
this url
https://community.oracle.com/thread/3689943?tstart=0

If you use normal page .jspx or .jsf be sure that the


button partailSubmit set to "false"

Reply

Anonymous June 15, 2016 at 12:02 AM

Hy Sameh!
Greetings
I want to run report with more than one parameters, I've tried
various things in my bean but couldn't do so, any suggestion
please?

Reply

Replies

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 30/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)

Sameh Nassar June 15, 2016 at 2:55 PM

It should be like:
Map m = new HashMap();
m.put("employeeId", empId);
m.put("param2", value2);
m.put("param3", value3);
.
.
runReport("empReport.jasper", m);

Reply

SREE SURESH June 27, 2016 at 10:58 PM

Thank you Very Much Mr.Sameh,


Very C lear and Easy to Understand...

Reply

Anonymous June 29, 2016 at 4:03 AM

Dear Sameh,

Thank you very much for the valuable post!


But I have a question regarding this post, in this post you are
talking about integrated server what if I have reports on Standalone
server?? how I can access those reports.

Thanks,
Best Wishes

Reply

Replies

Sameh Nassar July 4, 2016 at 1:20 AM

Jasper report is xml file will be included in the Ear file of


your application, so if you create ear file and deploy it in
standalone server it should work without any additional
steps or configurations

Reply

Used PC Distributor September 8, 2017 at 6:05 AM

Nice Blog Post !

Reply

Anonymous November 22, 2017 at 2:01 AM

Hello Mr Sameh,

Hope you are doing fine.

I have tried the example above with the following codes below..
however the report is not being displayed on the browser. the
browser page simply refreshes on itself. Any idea what could be
wrong please?

HttpServletResponse response = getResponse();


ServletOutputStream out = response.getOutputStream();
response.setHeader("C ache-C ontrol", "max-age=0");
response.addHeader("C ontent-Disposition", "attachment;

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 31/32
5/5/2018 Sameh Nassar: Using Jasper Report In ADF Application (Step-by-Step)
filename=report.pdf");

response.setC ontentType("application/pdf");
C lassLoader loader =
Thread.currentThread().getC ontextC lassLoader();
InputStream is =
loader.getResourceAsStream("C ontainerHistoricReport.jasper");
jasperPrint =JasperFillManager.fillReport(is,
null,beanC ollectionDataSource);

JasperExportManager.exportReportToPdfStream(jasperPrint, out);
FacesC ontext.getC urrentInstance().responseC omplete();

Reply

Replies

Sameh Nassar November 22, 2017 at 4:59 AM

- Any error appear in the log?


- Are you run in normal page or page fragment(.jsff)?
- Is in 11g or 12c application?
- Did you try to download my application and run it? is it
running successfully?
- Is button's (which you press on it to run the report)
partialSubmit="false"?

Reply

Unknown February 22, 2018 at 12:17 AM

Very good post. Thank you, you've helped me a lot. Keep up the
good work

Reply

Enter your comment...

Comment as: Alaa Ahmed (G Sign out

Publish Preview Notify me

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 32/32

You might also like