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();
reportBean.openUrlInNewWindow(url);
as in picture
4- Make a new java file which will be OracleReportBean (assume its name will be OracleReportBean.java) and write this code inside OracleReportBean.java:
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
setReportServerParam(RS_PARAM_STATUSFORMAT,STATUSFORMAT_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)mapKeys.next();
keyValueBuffer.append(map_key).append(param_equal).append(p_map.get(map_key));
if (mapKeys.hasNext()) {
keyValueBuffer.append(param_sep);
}
}
}
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 */
reportURL.append("http://");
reportURL.append(http_host);
if (http_port != null) {
reportURL.append(":").append(http_port);
}
/* Add "/" separator if necessary. */
if (servlet_path.indexOf("/") > 0) {
reportURL.append("/");
}
reportURL.append(servlet_path);
reportURL.append("?");
if (value_keyMap != null) {
reportURL.append(value_keyMap).append(param_sep);
}
/*Construct Report Server Parameter URL component*/
reportURL.append(buildKeyValueString(reportServerParams));
if (!reportServerParams.isEmpty()) {
reportURL.append(param_sep);
}
/*Construct Report Parameters URL Component*/
reportURL.append(buildKeyValueString(reportParams));
}
/***
* 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() {
constructURL();
return reportURL.toString();
}
public void openUrlInNewWindow(String url) {
ExtendedRenderKitService erks =
Service.getRenderKitService(FacesContext.getCurrentInstance(),
ExtendedRenderKitService.class);
StringBuilder strb = new StringBuilder("window.open('" + url + "');");
erks.addScript(FacesContext.getCurrentInstance(), strb.toString());
}
}
Oracle Report URL should be at this format
http://myServer:myport/reports/rwservlet?destype=cache&desformat=PDF&report=myreport.jsp&myparameter=myvalue
5- Save and Run the application.
You can see other way to call oracle report from this link
http://sameh-nassar.blogspot.com/2012/05/call-oracle-reports-from-your-adf.html
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();
reportBean.openUrlInNewWindow(url);
as in picture
4- Make a new java file which will be OracleReportBean (assume its name will be OracleReportBean.java) and write this code inside OracleReportBean.java:
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
setReportServerParam(RS_PARAM_STATUSFORMAT,STATUSFORMAT_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)mapKeys.next();
keyValueBuffer.append(map_key).append(param_equal).append(p_map.get(map_key));
if (mapKeys.hasNext()) {
keyValueBuffer.append(param_sep);
}
}
}
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 */
reportURL.append("http://");
reportURL.append(http_host);
if (http_port != null) {
reportURL.append(":").append(http_port);
}
/* Add "/" separator if necessary. */
if (servlet_path.indexOf("/") > 0) {
reportURL.append("/");
}
reportURL.append(servlet_path);
reportURL.append("?");
if (value_keyMap != null) {
reportURL.append(value_keyMap).append(param_sep);
}
/*Construct Report Server Parameter URL component*/
reportURL.append(buildKeyValueString(reportServerParams));
if (!reportServerParams.isEmpty()) {
reportURL.append(param_sep);
}
/*Construct Report Parameters URL Component*/
reportURL.append(buildKeyValueString(reportParams));
}
/***
* 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() {
constructURL();
return reportURL.toString();
}
public void openUrlInNewWindow(String url) {
ExtendedRenderKitService erks =
Service.getRenderKitService(FacesContext.getCurrentInstance(),
ExtendedRenderKitService.class);
StringBuilder strb = new StringBuilder("window.open('" + url + "');");
erks.addScript(FacesContext.getCurrentInstance(), strb.toString());
}
}
Oracle Report URL should be at this format
http://myServer:myport/reports/rwservlet?destype=cache&desformat=PDF&report=myreport.jsp&myparameter=myvalue
5- Save and Run the application.
You can see other way to call oracle report from this link
http://sameh-nassar.blogspot.com/2012/05/call-oracle-reports-from-your-adf.html
hi Sameh
ReplyDeletevery 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.
http://sameh-nassar.blogspot.ie/2012/05/call-oracle-reports-from-your-adf.html
DeleteHi xizoaziz,
ReplyDeleteYou are right but I think this is a problem concerned with Oracle Report not ADF, so I have no solution :(
i think this can be solved through Keymap value holds the sensitive information easily ..
Deletegr8 jop
mojtabanow.info
السلام عليكم
ReplyDeleteالاستاذ سامح
شكرا على المجهود الرائع وبالنسبة انا عملت الي انت قلت عله
بس مشعارف ازاي ابعت ال url للريبورت
وازاي احدد الريبورت سيرفر والبورت
ياريت توضحلي الخطوات بعد ما عملت Beanوال class
شكرا
وعليكم السلام
Deleteالمفروض انك منزل التقارير على سيرفر وانت بتنادي عليها فلابد من ان تكون عارف الاي بي والبورت بتاع السيرفر ولو في مشكلة عندك ممكن تبعتلى اميلك وانا ابعتلك أبليكيشن يشرحلك الطريقة دي
Other way to call oracle report and hide oracle parameters from URL see this post
ReplyDeletehttp://sameh-nassar.blogspot.com/2012/05/call-oracle-reports-from-your-adf.html
جزاك الله كل خير
ReplyDeleteبس اتمني
sample application
علشان انا مش اقدر اطبق الكود ده
وانتظار رد ان شاء الله
وجزاك الله خير
try this
Deletehttp://sameh-nassar.blogspot.com/2012/05/call-oracle-reports-from-your-adf.html
شكر ا سامح
ReplyDeleteمجهود رائع
كنت عاوز اعرف افضل طريقه لل Adf مع crystal reports
اسف محمد لم اتعامل مع ال
DeleteCrystal reports
من قبل بس ممكن تشتغل بال
Jasper Report
ولي مقال يوضح التعامل معه
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHi,
DeleteYou 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
http://sameh-nassar.blogspot.ie/2012/05/call-oracle-reports-from-your-adf.html
Hello,
ReplyDeleteYour 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?
Unfortunately ADF has no built in libraries for any reporting tools.
DeleteTo use reports in ADF you should use one of this:
1- Jasper Report
2- Call oracle report
3- Use oracle BI
السلام عليكم
ReplyDeleteازاى بجيب ال url
ارجو الاجابه فى اسرع وقت وشكراا
تقارير الاوراكل لابد من ان يتم نشرها على ريبورت سيرفر فيمكنك ان تسال الذي قام بانشاء التقرير اين تم نشر التقرير وماهو رابط التقرير والمتغيرات التي يجب ان ترسل للتقرير.
Deleteأو يمكنك ان تجرب هذه الطريقة ايضا
Deletehttp://sameh-nassar.blogspot.com/2012/05/call-oracle-reports-from-your-adf.html