/*===========================================================================+
| Controller to invoke XML Publisher report |
| |
+===========================================================================+
| HISTORY |
+===========================================================================*/
package xxcomp.oracle.apps.pos.orders.webui;
import com.sun.java.util.collections.Hashtable;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.http.HttpServletResponse;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.nav.OAButtonBean;
import oracle.apps.fnd.framework.webui.beans.nav.OAPageButtonBarBean;
import oracle.apps.pos.orders.webui.PosVpoMainCO;
import oracle.apps.xdo.XDOException;
import oracle.jdbc.OracleCallableStatement;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
// this is a custom utility class
import xxcomp.oracle.apps.xxprj.common.utils.BiPublisherHelper;
/**
* Controller for Exporting Purchase Orders on iSupplier View Purchase Order page
*/
public class XXExportPoDetailsCO extends PosVpoMainCO // this extension of page level controller
{
public static final String EXPORT_DATA_DEFINITION = "POEXPTEST"; //Data Definition code
public static final String EXPORT_CSV_TEMPLATE = "POEXPDELIM"; //Template Short Code
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Begin processRequest", 2);
// Find the application module
OAApplicationModule am =pageContext.getApplicationModule(webBean);
// Find the view object which is the base for displaying the resutls
// and which contains the PO_HEADER_ID that we want to pass to XMLP
// data template
OAViewObject vo = (OAViewObject)am.findViewObject("PosPOSummaryVO");
int resetMaxFetchSize = vo.getMaxFetchSize();
// We are interested to export all the rows from VO. -1 will ensure
// that we fetch every single row from ViewObject and by pass the VO_MAX_FETCH_SIZE
// profile value
vo.setMaxFetchSize(-1);
super.processRequest(pageContext, webBean);
/* Find the button XXExportDetailsBtn created using personalization */
OAPageButtonBarBean btnBar = (OAPageButtonBarBean)webBean.findChildRecursive("PageBtnRN");
OAButtonBean expDtlBtn = (OAButtonBean)btnBar.findChildRecursive("XXExportDetailsBtn");
if (expDtlBtn == null) {
pageContext.putDialogMessage
(new OAException ("Unable to find personalizatoin ID: XXExportDetailsBtn . Export Details button cannot be rendered", OAException.WARNING));
}
else {
// Set the fireAction so that when user click on the button we get an event in processFormRequest
expDtlBtn.setFireActionForSubmit("XXExportPoDetailsEvent",null,null,false);
}
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: End of processRequest", 2);
}
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean) {
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Begin of processFormRequest", 2);
super.processFormRequest(pageContext, webBean);
if ("XXExportPoDetailsEvent".equals(pageContext.getParameter(EVENT_PARAM)))
// User clicked on Export Details button. This is the same fireAction event
// that we have set on button above in processRequest method.
{
//The e-Text template
String strLayoutTemplate = EXPORT_CSV_TEMPLATE;
//Assign the file name for multiple PO Export
String strFileName = "PO_Details_Export.csv";
// Set output type to E-Text as we want a plain text output from delimiter based template
byte outputType = BiPublisherHelper.OUTPUT_TYPE_ETEXT;
String[] lPoHdrIds = null;
OAApplicationModule am = pageContext.getApplicationModule(webBean);
// Find the view object used for displaying the results
OAViewObject vo = (OAViewObject)am.findViewObject("PosPOSummaryVO");
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Populating the array with Ids", 2);
// View object is not yet executed, may be user did not perform a search
if (!vo.isExecuted()) return;
//View object is executed, Reset the row currency to before the first row
vo.reset();
// Create a string array to hold all po_header_id
lPoHdrIds = vo.getRowCount()>0?new String[vo.getRowCount()] : null;
// Populate array with PO_HEADER_ID from instance which is recently searched
for (int i=0; vo.hasNext(); i++) {
lPoHdrIds[i] = vo.next().getAttribute("PO_HEADER_ID").toString();
}
String strCall = "BEGIN PO_EXP_PKG.set_po_header_ids (?); END;";
OracleCallableStatement oca = (OracleCallableStatement) am.getOADBTransaction().createCallableStatement(strCall, am.getOADBTransaction().DEFAULT);
ArrayDescriptor ad;
ARRAY lPoHdrIdsArray=null;
//If we do not have list of header ids to process we can simply return
if (lPoHdrIds == null ) {
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Array to pass is null, lPoHdrIds="+ lPoHdrIds.toString(), 2);
throw new OAException("Failed to get list of Document Ids to be exported", OAException.INFORMATION);
}
try {
/*
* Create the array descriptor for collection VARCHAR2_TABLE_100
* Using the array descriptor, we can create an SQL Array object
* which can be passed to pl/sql
*/
ad = ArrayDescriptor.createDescriptor("VARCHAR2_TABLE_100", am.getOADBTransaction().getJdbcConnection());
lPoHdrIdsArray = new ARRAY (ad, am.getOADBTransaction().getJdbcConnection(),lPoHdrIds);
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Array descriptor is defined and Array is ready to pass", 2);
}
catch (SQLException e) {
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Exception:" + e.getMessage() , 2);
throw new OAException ("Exception: Failed to create array descriptor: "+e.getMessage());
}
/*
* Invoke the procedure to set the global pl/sql collection variable
*/
boolean bInvokeXMLP = false;
try {
if (lPoHdrIdsArray==null) return; //Array does not contain anything
oca.setARRAY(1, lPoHdrIdsArray);
oca.execute();
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Procedure executed:" + strCall , 2);
//We have successfully passed array to procedure
bInvokeXMLP = true;
}
catch (SQLException e) {
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Exception:" + e.getMessage(), 2);
throw new OAException ("Exception:Failed to invoke procedure to pass array"+e.getMessage());
}
//If flag to invoke the XMLP report is not set we can simply return
if (!bInvokeXMLP) return;
/*
* Invoke xml publisher data template which will read the data from the collection table
* initialized above and generate the final output
*/
if (pageContext.isLoggingEnabled(2)) pageContext.writeDiagnostics(this, "XX: Invoking the Bi Report App=XXPRJ"+"DataDef="+EXPORT_DATA_DEFINITION
+", Layout="+strLayoutTemplate+", file="+strFileName, 2);
Hashtable prms = new Hashtable(1); //Create a hashtable for data template parameters
prms.put("P_ORG_ID", 204); //Set parameter values
try {
String strApp = "XXPRJ"; //Application name under which the data template and layout are registered
// Get an instance of the BiPublisherHelper utility to run the report
BiPublisherHelper biHelper = BiPublisherHelper.createInstance(pageContext,am);
if (prms != null) {
// Set the data template parameters if any
biHelper.setDataTemplateParams(prms);
}
// Run the xml publisher report
biHelper.runBiReport(strApp,EXPORT_DATA_DEFINITION,strApp,EXPORT_CSV_TEMPLATE,outputType);
// Show the report output as file download dialog box
biHelper.showOutputAsDownload("PoDetialsExport.csv");
}
catch (SQLException e) {
System.out.println("::::ERROR:::: Failed to find data template "+EXPORT_DATA_DEFINITION);
e.printStackTrace();
pageContext.putDialogMessage(new OAException ("Exception:"+e.getMessage(),OAException.ERROR ));
}
catch (XDOException xe) {
System.out.println("::::ERROR:::: Failed to execute data template "+EXPORT_DATA_DEFINITION);
xe.printStackTrace();
pageContext.putDialogMessage(new OAException ("Exception:"+xe.getMessage(),OAException.ERROR ));
}
catch (IOException ioe) {
System.out.println("::::ERROR:::: Failed to execute layout template "+EXPORT_CSV_TEMPLATE);
ioe.printStackTrace();
pageContext.putDialogMessage(new OAException ("Exception:"+ioe.getMessage(),OAException.ERROR ));
}
catch(Exception e)
{
pageContext.putDialogMessage( new OAException(e.getMessage(), OAException.ERROR));
}
}
}
}
Comments
Thanks for the wonderful article.
Cheer s,
Senthil
Great job Friend.
Where can we get BiPublisherHelp er bean to include in my project?
Just before the controller code you can find a hyperlink to download the source code of BiPublisherHelp er
Thank You.
We are starting usin Bi publisher and OAF extension in R12 upgrade, and my question is about step4 : how to Invoke the above XML Publisher EText report from OA Framework - using BIPublisherUtil ity .
Thank you
Tha nks for the comment.
I did not get your comment properly. Do you want to know how to invoke XML Publisher report from OAF using XML Publisher, or you already got the answer from this article? Let me know if you need any further details.
Thank s
Bhavik
Thank you for answering. Yes my question is how to invoke XML Publisher report from OAF using XML Publisher.
Tha nk you a gain and have nice day.
Abdelmale k
Great job..It ll be very useful.
thank you
i tried use your code,but i am unable to get a report out.
i have stucked in while calling the Bireport() method and templete initialization parameters.
it is always throwing the Stckoverflow error is getting.
colud you please help me out how to call XML report calling from OAF
Thanks for making the world better :)
RSS feed for comments to this post