OAF page to UPLOAD the data from excel sheet to the database table
UPLOAD BUTTON (logic below):
Excel sheet column structure:
Table Structure:
Code inside Controller:
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
String filename = null;
String fname = null;
String ext = null;
pageContext.writeDiagnostics(this,"Inside PFR..",1);
if(pageContext.getParameter("UploadBtn") != null) //ID of the Upload button
{
DataObject upload = pageContext.getNamedDataObject("FileUpload"); //import oracle.cabo.ui.data.DataObject;
//"FileUpload" is the ID of the item with style "messageFileUpload".
try {
filename = (String)upload.selectValue(null, "UPLOAD_FILE_NAME");
int mid = filename.lastIndexOf(".");
fname = filename.substring(0, mid);
ext = filename.substring(mid + 1, filename.length());
}
catch (NullPointerException e) {
pageContext.writeDiagnostics(this, "HAR$ - Inside exceptionpart: " + e, 1)
} //end of try catch
if (!"csv".equalsIgnoreCase(ext) || !"CSV".equalsIgnoreCase(ext)){
throw new OAException("Please upload only .csv extension file", OAException.ERROR);
}
//To delete the temp table before uploading the data into the temp table everytime
String sqlDelete = "BEGIN delete from xxcust_lifecycle_tmp; END;";
CallableStatement callstmt = (CallableStatement)am.getOADBTransaction().createCallableStatement(sqlDelete,1);
try {
callstmt.execute();
}
catch (Exception e) {
pageContext.writeDiagnostics(this, "Error during delete life cycle table" +e, 1);
}
BlobDomain uploadstream = (BlobDomain)upload.selectValue(null, filename);
oracle.jbo.domain.Number batchID = am.getOADBTransaction().getSequenceValue("APPS.XXCUST_LIFECYCLEUPLD_SEQ");
Serializable param[] = {uploadstream, filename, batchID};
Class classparam[] = {BlobDomain.class, String.class, oracla.jbo.domain.Number.class};
am.invokeMethod("DataUpload", param, classparam);
//validateData
this.validateData(am, batchID);
} // end of IF
}
NOTE: XXCUSTlifeCycleUploadEO entity object should be already created to load the data from the excel to the table xxcust_life_cycle_data.
//validate Data method in controller
public void validateData(OAApplicationModule am, Number batchID)
{
am.getOADBTransaction().writeDiagnostics("Inside validateData..");
OADBTransaction oadbtransaction = am.getOADBTransaction();
StringBuffer str = new StringBuffer();
str.append("BEGIN xxcust_vldt_lfcycle_data( p_batch_id => :1 ); END;");
OracleCallableStatement ocs = (OracleCallableStatement)oadbtransaction.createCallableStatement(str.toString(), 1);
try {
ocs.setNumber(1, (NUMBER)batchID);
ocs.execute();
}
catch (Exception e) {
throw OAException.wrapperException(e);
}
}
Code inside AM:
Comments
Post a Comment