You can check this for step by step calling jasper report
http://sameh-nassar.blogspot.ie/2012/12/using-jasper-report-in-adf-application.html
One of the solutions for generating reports when you use JDeveloper is using Jasper Report.
Jasper report is some of libraries (.Jar files) and .xml or .jrxml file that represent your report.
One of the easy ways to write .xml file is using IReport program. IReport is a program that manage you to design your report graphically then save your report to xml or jrxml file. From JDeveloper after you add jasper reports libraries to your project you can read your report (.xml file) and print it as PDF file or Excel File or Jasper Viewer.
http://sameh-nassar.blogspot.ie/2012/12/using-jasper-report-in-adf-application.html
One of the solutions for generating reports when you use JDeveloper is using Jasper Report.
Jasper report is some of libraries (.Jar files) and .xml or .jrxml file that represent your report.
One of the easy ways to write .xml file is using IReport program. IReport is a program that manage you to design your report graphically then save your report to xml or jrxml file. From JDeveloper after you add jasper reports libraries to your project you can read your report (.xml file) and print it as PDF file or Excel File or Jasper Viewer.
Jasper Report Libraries is:
1-commons-digester-1.7.jar
2-itext-1.4.5.jar
3-jasperreports-3.0.0.jar
4-poi-2.5.1-final-20040804.jar
5- jasper-compiler-jdt-5.5.15.jar
2-itext-1.4.5.jar
3-jasperreports-3.0.0.jar
4-poi-2.5.1-final-20040804.jar
5- jasper-compiler-jdt-5.5.15.jar
You Can Download IReport From :
To configure your application to use Jasper Reports:
1- Add jasper report libraries to your project.
2- In web.xml add this
< resource-ref>
< res-ref-name> jdbc/OracleDBConnectionDS < /res-ref-name>
< res-type> javax.sql.DataSource < /res-type>
< res-auth> Container < /res-auth>
< /resource-ref>
3- From backingbean write this method:
----------- Imports ----------------
import java.io.*;
import java.util.*;
import java.sql.Connection;import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.InitialContext;import javax.naming.NamingException;
import net.sf.jasperreports.engine.*;
import java.util.*;
import java.sql.Connection;import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.InitialContext;import javax.naming.NamingException;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
----------------------------------------
public void printReport() throws FileNotFoundException, JRException, NamingException, SQLException, IOException {
InputStream input = new FileInputStream(new File("c:/yourJasperReport.xml"));
JasperDesign design = JRXmlLoader.load(input);
JasperReport report = JasperCompileManager.compileReport(design);
JasperReport report = JasperCompileManager.compileReport(design);
Map parameters = new HashMap();
// parameters.put("jasperParamenterName", "ParameterValue"); Used if you want to pass a parameter to a jasper report
InitialContext initialContext = new InitialContext();
DataSource ds = (DataSource)initialContext.lookup("java:comp/env/jdbc/OracleDBConnectionDS"); // get from your application module configuration
Connection conn = ds.getConnection();
JasperPrint print = JasperFillManager.fillReport(report, parameters, conn);
///// For printing report as PDF file ////////
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream(); JasperExportManager.exportReportToPdfStream(print,byteArrayOutputStream);
///// For printing report as PDF file ////////
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream(); JasperExportManager.exportReportToPdfStream(print,byteArrayOutputStream);
out.write(byteArrayOutputStream.toByteArray());
out.flush();
out.close();
FacesContext.getCurrentInstance().responseComplete();
//////// For printing report as excel file //////
OutputStream ouputStream = new FileOutputStream(new File("c:/yourReport.xls")); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); JRXlsExporter exporterXLS = new JRXlsExporter();
OutputStream ouputStream = new FileOutputStream(new File("c:/yourReport.xls")); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, print); exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);
exporterXLS.exportReport();
ouputStream.write(byteArrayOutputStream.toByteArray());
ouputStream.flush();
ouputStream.close();
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler c:/yourReport.xls");
///// for printing report as a jasper report viewer /////
JasperViewer.viewReport(print, true);
///// for printing report as a jasper report viewer /////
JasperViewer.viewReport(print, true);
}
For More Information About Using Jasper Report :
Hi,
ReplyDeleteHow Can i do parameter page to pass to jasper?
Similar to Oracle forms unbound items / Reports Integration.
Hi Bernat,
ReplyDeleteYou can make a parameter page and bind its fields in backingbean and set report parameter with the entered data as:
in parameter page put af:inputText and set its value with variable in backingbean (assume the variable is "param1")
in Jasper report bean set parameter as
Map parameters = new HashMap();
parameters.put("jasperParamenterName", "Param1");
Thanks Sameh
ReplyDeletebut your code work only in server side , can i use some thing to view report in client side ,
ReplyDeletereally it is urgent
Hi, i have my report an run ok but when execute JasperViewer.viewReport(print, true); my weblogic server (integrated with jdeveloper) is shutdown. Can you help me? I have j developer 11g release 1.
ReplyDeleteThanks
use JasperViewer.viewReport(print, false);
ReplyDeleteHi, I m getting this error after running report, "XML-20149: (Error) Element 'jasperReport' used but not declared".
ReplyDeleteHow to correct this?
I think you not follow my steps correctly because I didn't write "jasperReport" so, check your code and if the problem not solved send me you code in my email samehnassar39@gmail.com.
ReplyDeleteHi, I actually get the same error..
ReplyDeleteParse Error at line 2 column 14: : XML-20149: (Error) Element 'jasperReport' used but not declared.
org.xml.sax.SAXParseException: : XML-20149: (Error) Element 'jasperReport' used but not declared.
at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:422)
at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:287)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:343)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:226)
at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:173)
at org.apache.commons.digester.Digester.parse(Digester.java:1745)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:238)
.
.
.
.
.
this happened when executing line
JasperDesign design = JRXmlLoader.load(input);
tools that i use are :
Jdeveloper 11.1.1.4.0 and JasperSoft iReport Designer 4.0.2
regards,
Hi,
ReplyDeletecheck the version of jasper library because every version of IReport should use a specific version of jasper report. Try to use IReport version 3.0.
Regards,
Thanks Sameh for This nice topic
ReplyDeleteits very usefull for me
Thanks again for share
Thanks Sameh for the nice and useful post
ReplyDeleteHI Samesh,
ReplyDeletewe are entity object based on transient attributes and view object based on this entity now we want to pass data in the view object to generate jasper report so instead of using ds can we use map.put(".jrxml parameter 1"," value of view attribute1")
I already use map in my code you will find this line Map parameters = new HashMap();
Deletewhich hold all your report parameters
i had try the code and it success.
ReplyDeletebut when i closed the pdf file or jasper view report, the weblogic force to shutdown.
i used jdev adf 11.1.1.5.0.anybody knows
TQ
Hi,
Deletetry to write JasperViewer.viewReport(print, false);
instead of JasperViewer.viewReport(print, true);
Hi Sameh,
ReplyDeleteyour code work only in server side , can i use some thing to view report in client side
I will make a new post for jasper, I will explain it in more detail.
DeleteCheck this
Deletehttp://sameh-nassar.blogspot.com/2012/12/using-jasper-report-in-adf-application.html
Hi Sameh,
ReplyDeleteCould you please tell me the steps after downloading all these package.
i'm new in Jdev 11g but i can understand clear steps so ...
I will make a new post for jasper, I will explain it in more detail. Just follow my blog this week.
DeleteRegards
Check this http://sameh-nassar.blogspot.com/2012/12/using-jasper-report-in-adf-application.html
Deleteجزاك الله خيرا
ReplyDeletetahnk sameh
ReplyDeletewhich better using oracle reports with xml publisher or using jasper
- XML Publisher is part of Oracle BI you should setup OBI environment and customer will pay licence for it but it has a good features like generated custom reports.
Delete- Jasper is xml file no need for report server to run, it will be included with in the application war file and it is free (no licence required) but it is static report.
So it depending on the customer requirements and how the customer is big, some customers can pay licence for reporting and other no.
i have used same procedure but run report button do nothing without any error
ReplyDeleteBe sure button autoSubmit property set to "false"
DeletePartialSubmit?? there is no autosubmit option in button property
ReplyDeleteSorry, yes it is partialSubmit="false"
Delete