Using Jasper Report in ADF Application (Step-by-Step)
Using Jasper Report in ADF Application (Step-by-Step)
Sameh Nassar
This blog is concerned with the ADF/BPM technology provided by Oracle. I Hope this blog helps fellow
Oracle ADF/BPM Developers
Followers
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)
Visitors
2,103 Pageviews
Apr. 05th - May. 05th
Popular Posts
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 ...
Total Pageviews
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
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)
then you should call the jasper report like this method
runReport("empReport.jasper", m);
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
---------------------------------------------------------------
-----------------------------------------------
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 }
---------------------------------------------------------------
-----------------------------------------
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
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 }
---------------------------------------------------------------
-----------------------------------------------------------
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:
you can get ojdbc jar file in your middleware home like:
C:\Oracle\Middleware\wlserver_10.3\server\lib and search for
ojdbc6.jar
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)
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:
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)
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)
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
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)
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>
function newWindow()
{
document.getElementById("f1").target = "_blank;targetfeatures=toolbar=no
location=no directories=no menubar=no";
}
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>
To call this function add button or link and inside this link add clientLister as:
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)
83 comments:
Very Nice and easy to understand. thanks for sharing such a nice
content.
Reply
Replies
Reply
Perfect explanation
Reply
Reply
Replies
ﺷﻛرا ﻟك
Reply
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?
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
Hi Rashid,
Regards,
Reply
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.
Reply
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
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)
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
Hi,
I do understanding what is the meaning of generate the
jasper report by a view??
Reply
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)
Any help?
Thanks.
Reply
Replies
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
Hi Samesh Sir,
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
Hi Rahul,
Regards,
Reply
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?
Reply
Replies
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:
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
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";
}
Reply
HiSameh,
Thank you so much for your clear explanation:)
Ellerine sağlık ;)
Betül
Reply
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)
Hi,
I try your scenario put it work without error. You can send
your code in my email to check it.
Regards,
Reply
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
Hi,
Reply
Hi,
Reply
Replies
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)
ﺟزاك ﷲ اﻟف ﺧﯾر اﺑداع ﻓﻲ اﻟﺷرح واﺳﻠوب اﻟﻌرض وﻓﻘك ﷲ ﻟﻣﺎ ﯾﺣﺑﮫ وﯾرﺿﺎه
Reply
Replies
ﺷﻛرا ﻟك
Reply
Reply
Replies
Thank You...
Reply
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
Hi,
Reply
ﻟذﻟك ﺗﺳﺗطﯾﻊ اﯾﺻﺎل.ﻣﺎﯾﻣﯾزك ﻋن اﻟﻘﯾﺔ أﻧك ﺗﺷرح ﺑﺎﻟﺗﻔﺻﯾل وﺗذﻛر ﻛل ﺷﻲء ﺣﺗﻰ اﻟﺗﻔﺎﺻﯾل اﻟﺑدﯾﮭﯾﺔ
اﻟﻣﻌﻠوﻣﺔ ﻟﻠﻘﺎرء ﺑﺷﻛل ﺳﻠس.
ﺷﻛرا ﻟك.
Reply
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
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
Dear Sameh
Thanks a lot , it works.
Reply
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
Thanks
Reply
Reply
Replies
Thanks
Reply
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)
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;
}
Reply
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
Reply
Replies
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,
Thanks Ahmed :)
Reply
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.
Thanks
Reply
Dear Sameh,
Aslam u Alakum,
When use new window code in adf page for report . The calling
button disabled . C an u please help me
Reply
Replies
Hi,
you can use af:commandLink with styleC lass="x7j
p_AFTextOnly" instead of af:commandButton
Reply
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
Thank You...
Reply
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
Hi ,
Thanks Jamal.
Reply
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
SHAN,
Try to add this java script in the .jsf page or in the page
template
Reply
Dear Sameh,
Well, I have a question regarding this post is can I select more than
one employee and display their data in table.
Best Regards,
Reply
Replies
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
Reply
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)
Reply
Replies
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
Reply
Dear Sameh,
Thanks
Reply
Replies
Reply
Reply
Replies
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
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
Reply
Replies
Reply
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)
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
Reply
Dear Sameh,
Thanks,
Best Wishes
Reply
Replies
Reply
Reply
Hello Mr Sameh,
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?
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
Reply
Very good post. Thank you, you've helped me a lot. Keep up the
good work
Reply
http://sameh-nassar.blogspot.com.eg/2012/12/using-jasper-report-in-adf-application.html 32/32