Monday, July 26, 2010

Call 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 oracle reports.

1- Create new ADF Application and make new .jspx page (this page will be a parameter page which will send the parameters to the report).

2- Insert inside page inputTexts which will hold the parameters and insert one commandButton which will run the report.

3- Bind the command button to the method in backbean and write this code:
OracleReportBean reportBean =
new OracleReportBean("oracleServerId", "Port", null);
reportBean.setReportServerParam(OracleReportBean.RS_PARAM_DESTYPE,"DisplayType");// which will be one of the [cashe - file - mail - printer]
reportBean.setReportServerParam(OracleReportBean.RS_PARAM_DESFORMAT,"Format"); // Which will be onr of the [HTML - HTML CSS - PDF - SPREADSHEET- RTF].
reportBean.setReportParameter(parameterName1, parameterValue1);// as report name
reportBean.setReportParameter(parameterName2, parameterValue2);
reportBean.setReportParameter(parameterName3, parameterValue3);
String url = reportBean.getReportServerURL();
as in picture

4- Make a new java file which will be OracleReportBean (assume its name will be and write this code inside

import java.util.HashMap;
import java.util.Iterator;

import javax.faces.context.FacesContext;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

* This bean performs the following functions:
* Constructing the Report URL with various parameters passed in by client.
* Sending the report request.
* Execute printed report and retrieve return status in the indicated format.
* Execute a binary report (PDF, RTF, XML, with DESTYPE CACHE) and return the
* InputStream for processing.
public class OracleReportBean {

/* Report Servlet Host Settings */
private String http_host = null;
private String http_port = null;

/* Default path as per generic Oracle Appserver install */
private String servlet_path = "/reports/rwservlet";

/* Report Servlet URL params */
public static final String RS_PARAM_SERVER = "server";
public static final String RS_PARAM_USERID = "userid";
public static final String RS_PARAM_REPORT = "report";
public static final String RS_PARAM_ENVID = "envid";
public static final String RS_PARAM_DESTYPE = "destype";
public static final String RS_PARAM_DESFORMAT = "desformat";
public static final String RS_PARAM_STATUSFORMAT = "statusformat";
public static final String RS_PARAM_DESNAME = "desname";
public static final String RS_PARAM_PAGESTREAM = "pagestream";
public static final String RS_PARAM_DELIMITER = "delimiter";
public static final String RS_PARAM_ORIENTATION = "orientation";
public static final String RS_PARAM_DISTRIBUTE = "distribute";
public static final String RS_PARAM_FILETYPE = "FILETYPE";
public static final String RS_PARAM_REP_VA = "REP_VA";

private String value_keyMap = null;

/* Static values for destination formats */
public static final String DESFORMAT_PDF = "PDF";
public static final String DESFORMAT_HTML = "HTML";
public static final String DESFORMAT_POSTSCRIPT = "POSTSCRIPT";
public static final String DESFORMAT_DELIMITED = "DELIMITED";
public static final String DESFORMAT_XML = "XML";
public static final String DESFORMAT_RTF = "RTF";

/* Static values for destination types*/
public static final String DESTYPE_MAIL = "mail";
public static final String DESTYPE_PRINTER = "printer";
public static final String DESTYPE_FILE = "file";
public static final String DESTYPE_LOCAL_FILE = "localFile";
public static final String DESTYPE_CACHE = "cache";

/* Static values for distribute */
public static final String DISTRIBUTE_YES = "YES";
public static final String DISTRIBUTE_NO = "NO";

/*Static values for status format */
public static final String STATUSFORMAT_XML = "XML";
public static final String STATUSFORMAT_HTML = "HTML";

/* Static values for report orientation */
public static final String ORIENTATION_PORTRAIT = "PORTRAIT";
public static final String ORIENTATION_LANDSCAPE = "LANDSCAPE";
public static final String ORIENTATION_DEFAULT = "DEFAULT";

/* HashMap to hold individual report parameters*/
private HashMap reportParams = new HashMap();

/* HashMap to hold report server params */
private HashMap reportServerParams = new HashMap();

/* Report Servlet */
private StringBuffer reportURL = new StringBuffer();
// private String XMLReturnStatus = null;

* Constructor
public OracleReportBean(String p_http_host, String p_http_port,
String p_servlet_path) {
http_host = p_http_host;
http_port = p_http_port;

/* If the servlet path is null, we assign the default path. */
if (p_servlet_path != null) {
servlet_path = p_servlet_path;

/* Default the status format to XML


* Private utility methods ...
private String buildKeyValueString(HashMap p_map) {

String map_key = null;
String param_sep = "&";
String param_equal = "=";
StringBuffer keyValueBuffer = new StringBuffer();

if (!p_map.isEmpty()) {

Iterator mapKeys = p_map.keySet().iterator();

while (mapKeys.hasNext()) {
map_key = (String);

if (mapKeys.hasNext()) {
return keyValueBuffer.toString();

/* Construct the URL for accessing the Oracle Reports Servlet */

private void constructURL() {
String param_sep = "&";

/* Clearout current URL */
reportURL = new StringBuffer();

/* HOST Section */


if (http_port != null) {

/* Add "/" separator if necessary. */
if (servlet_path.indexOf("/") > 0) {


if (value_keyMap != null) {

/*Construct Report Server Parameter URL component*/

if (!reportServerParams.isEmpty()) {

/*Construct Report Parameters URL Component*/

* Getters and Setters for the Reports Servlet
* URL parameter values.

public void setReportServerParam(String p_param, String p_value) {
reportServerParams.put(p_param, p_value);

public String getReportServerParam(String p_param) {
if (reportServerParams.containsKey(p_param)) {
return (String)reportServerParams.get(p_param);
} else {
return null;

/* Set/Get the value of a Reports KeyMap file */

public void setKeyMap(String p_keyMap) {
value_keyMap = p_keyMap;

public String getKeyMap() {
return value_keyMap;

/* Add/Update and retrieve individual report parameters */

public void setReportParameter(String paramName, String paramValue) {

reportParams.put(paramName, paramValue);

public String getReportParameter(String paramName) {

if (reportParams.containsKey(paramName)) {
return (String)reportParams.get(paramName);
} else {
return null;


* Construct and return a URL that can be used to execute the report.
public String getReportServerURL() {
return reportURL.toString();

public void openUrlInNewWindow(String url) {
ExtendedRenderKitService erks =
StringBuilder strb = new StringBuilder("'" + url + "');");
erks.addScript(FacesContext.getCurrentInstance(), strb.toString());

Oracle Report URL should be at this format

5- Save and Run the application.

You can see other way to call oracle report from this link


  1. hi Sameh
    very nice idea but is there any way to hide parameter in URL because any one could take the URL as a copy and past it in in a new browser even if he have no privilege to see the report.


  2. Hi xizoaziz,

    You are right but I think this is a problem concerned with Oracle Report not ADF, so I have no solution :(

    1. i think this can be solved through Keymap value holds the sensitive information easily ..

      gr8 jop

  3. السلام عليكم

    الاستاذ سامح

    شكرا على المجهود الرائع وبالنسبة انا عملت الي انت قلت عله
    بس مشعارف ازاي ابعت ال url للريبورت
    وازاي احدد الريبورت سيرفر والبورت
    ياريت توضحلي الخطوات بعد ما عملت Beanوال class


    1. وعليكم السلام
      المفروض انك منزل التقارير على سيرفر وانت بتنادي عليها فلابد من ان تكون عارف الاي بي والبورت بتاع السيرفر ولو في مشكلة عندك ممكن تبعتلى اميلك وانا ابعتلك أبليكيشن يشرحلك الطريقة دي

  4. Other way to call oracle report and hide oracle parameters from URL see this post

  5. جزاك الله كل خير
    بس اتمني
    sample application
    علشان انا مش اقدر اطبق الكود ده

    وانتظار رد ان شاء الله

    وجزاك الله خير

    1. try this

  6. شكر ا سامح
    مجهود رائع
    كنت عاوز اعرف افضل طريقه لل Adf مع crystal reports

    1. اسف محمد لم اتعامل مع ال 
      Crystal reports
      من قبل بس ممكن تشتغل بال
      Jasper Report
      ولي مقال يوضح التعامل معه

  7. This comment has been removed by the author.

  8. This comment has been removed by the author.

    1. Hi,
      You not need to attach rdf file in the application because you just call the rdf report. You should run the rdf report in report server as if you call it from Oracle Forms. This way of calling Oracle Report has a problem which is the report parameters will appear in URL. I prefer to use this method to all Oracle report

  9. Hello,

    Your tutorials are really helpful. Can you please suggest any possible way for generating reports using Jdeveloper and Oracle ADF without using any third party tool/ API? i.e. Is there any built-in way to do that?

    1. Unfortunately ADF has no built in libraries for any reporting tools.
      To use reports in ADF you should use one of this:
      1- Jasper Report
      2- Call oracle report
      3- Use oracle BI

  10. السلام عليكم
    ازاى بجيب ال url
    ارجو الاجابه فى اسرع وقت وشكراا

    1. تقارير الاوراكل لابد من ان يتم نشرها على ريبورت سيرفر فيمكنك ان تسال الذي قام بانشاء التقرير اين تم نشر التقرير وماهو رابط التقرير والمتغيرات التي يجب ان ترسل للتقرير.

    2. أو يمكنك ان تجرب هذه الطريقة ايضا