Building a generic upload page in OA Framework

Let’s built a very simple page in OAF to enable end-users to upload files to the FND_LOBS table.
After they have been inserted in the table you have all kinds of options, use them as attachments or save them on the filesystem of the server, I use them as input for interfaces for example.

First of all we need some standard stuff from Oracle (actually the VO for FND_LOBS),
so zip the contents of the $JAVA_TOP/oracle/apps/fnd/server and unzip in your JDEV_USER_HOME/myclasses directory.

Create a new OA Workspace and project…

image

 

 

 

 

 

Set the default package to something like xx.oracle.apps.fnd.upload.webui
I use webui as default package as i plan to create a custom page and controller which reside in the webui package.

image

 

 

 

 

 

 

 

 

 

 

Click next twice to get to step 3…

image

 

 

 

 

 

 

 

 

 

 

First the DBC file is needed, you can find this file on the server or via a URL, see this article for details.
Enter a EBS username and password and a valid application (short name) and responsibility (key).
Off course the EBS user you just entered should have access to this responsibility.

Create a new business component.

image

 

 

 

 

 

 

 

 

Leave the package name as is…

image

 

 

 

 

 

 

 

 

 

Press next and press finish on page 2.

Now we can import the files you copied from the server to myclasses.

image

 

 

 

 

 

 

 

 

Find your myclasses directory and goto myclasses/oracle/apps/fnd/server, there should be a server.xml file over there which we will import.

image

 

 

 

 

 

 

 

 

 

 

You can get following message, answer with Yes.

image

 

 

 

 

 

Your project should now look like below:

image

 

 

 

 

When you open oracle.apps.fnd.server you should see all standard FND objects, we are interested in FndLobsVO, which should be there as well.

Now let’s create the page from which we will upload the files.
Click File – New – Web Tier – OA Components and choose Page, name it something like xxUploadPG.

image

 

 

 

 

 

 

 

 

 

 

 

image

 

 

 

 

 

You will see the default Page Layout Region which i renamed to pageLayoutRegion.
Set the following properties:

  • AM Definition to oracle.apps.fnd.server.OAAttachmentsAM
  • Window title to something like: xx Web Upload
  • Title to something like: Web Upload

image

 

 

 

image

 

 

 

 

 

 

 

 

 

 

 

Add an item to the pageLayout region with Item Style messageFileUpload.

image

 

 

 

 

Enter properties as follows:

  • View Instance: FndLobsVO
  • Data Type: BLOB
  • View Attribute: FileData (This is the BLOB column FILE_DATA in FND_LOBS)
  • Prompt to something like: File Name

image

 

 

 

 

 

 

 

 

 

 

 

 

Add a region of type pageButtonBar to hold the buttons and add a Submit and Cancel button (item style submitButton) to this region so we are able to add code later on to submit the upload of the file.
If you run your page, it will look like this now:

image

To be able to cancel without any validation and return to the homepage we have to change 2 properties of the cancel button first, set Disable Server Side Validation and Disable Client Side Validation to True.

image

Add a controller to the pageLayout region.

image

NOTE: For this example we will add all code to the controller, in real situations you should consider moving parts of the code to the AM and/or EO to get cleaner code in the controller.

This it the complete code of the controller xxUploadCO.java, i hope the inline comments will do all the explanation:

/*===========================================================================+
|   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
|                         All rights reserved.                              |
+===========================================================================+
|  HISTORY                                                                  |
|  1.0  RJUNGERIUS   07-APR-11 Initial creation                             |
+===========================================================================*/
package xx.oracle.apps.fnd.upload.webui;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.apps.fnd.framework.webui.OAWebBeanConstants;

import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.OAException;

import oracle.jbo.Row;

import oracle.apps.fnd.framework.webui.beans.message.OAMessageFileUploadBean;
import oracle.apps.fnd.framework.webui.OADataBoundValueViewObject;

/**
* Controller for …
*/
public class xxUploadCO extends OAControllerImpl
{
public static final String RCS_ID=”$Header$”;
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, “%packagename%”);

/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
OAViewObject vo = (OAViewObject)am.findViewObject(“FndLobsVO”);
// Per the coding standards, this is the proper way to initialize a
// VO that is used for both inserts and queries.  See View Objects
// in Detail in the Developer’s Guide for additional information.
if (!vo.isPreparedForExecution())
{
vo.executeQuery();
}
Row row = vo.createRow();
vo.insertRow(row);
// Required per OA Framework Model Coding Standard M69
row.setNewRowState(Row.STATUS_INITIALIZED);

// Initialize columns
// Set column FILE_FORMAT to IGNORE, this column is used for the online help index
row.setAttribute(“FileFormat”,”IGNORE”);
// set upload date to current date and time
row.setAttribute(“UploadDate”, am.getOADBTransaction().getCurrentDBDate());
// set program name to the name of this module, i.e xxUpload
// This way it is easy to identify that the record was inserted by this customization
row.setAttribute(“ProgramName”, “xxUpload”);
// get a handle to the uploadbean
OAMessageFileUploadBean uploadBean = (OAMessageFileUploadBean)webBean.findChildRecursive(“fileName”);
// set file name display
OADataBoundValueViewObject displayNameBoundValue = new OADataBoundValueViewObject(uploadBean, “FileName”);
uploadBean.setAttributeValue(DOWNLOAD_FILE_NAME,displayNameBoundValue);
// set content type (MIME)
OADataBoundValueViewObject contentBoundValue = new OADataBoundValueViewObject(uploadBean, “FileContentType”);
uploadBean.setAttributeValue(FILE_CONTENT_TYPE, contentBoundValue);
}

/**
* 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)
{
super.processFormRequest(pageContext, webBean);
if (pageContext.getParameter(“cancelButton”) != null)
{
// Perform a rollback on the database
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.getTransaction().rollback();
// cancel button pressed, return to homepage
pageContext.forwardImmediately(“OA.jsp?OAFunc=OAHOMEPAGE”,
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
false, // do not retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
else if (pageContext.getParameter(“submitButton”) != null)
{
// Perform a commit on the database
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.getTransaction().commit();
// Display upload confirmation message
OAViewObject vo = (OAViewObject)am.findViewObject(“FndLobsVO”);
oracle.jbo.domain.Number fileId = (oracle.jbo.domain.Number)vo.getCurrentRow().getAttribute(“FileId”);
String fileName = (String)vo.getCurrentRow().getAttribute(“FileName”);
OAException confirmMessage = new OAException(“File “+fileName+” uploaded succesfully with ID “+fileId+”.”,OAException.CONFIRMATION);
pageContext.putDialogMessage(confirmMessage);
// return to upload page
pageContext.forwardImmediately(“OA.jsp?page=/xx/oracle/apps/fnd/upload/webui/xxUploadPG”,
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}

}

}

Make and rebuild the complete project and run the page from within JDeveloper.
If you followed all steps then you should be able to select a file and after pressing Submit it will be inserted in FND_LOBS and the confirmation message is shown as below:

image

To deploy copy the controller java file and the page xml file to $JAVA_TOP/xx/oracle/apps/fnd/upload/webui.
Compile the java file.
Import the page with the following command:

java oracle.jrad.tools.xml.importer.XMLImporter \
$JAVA_TOP/xx/oracle/apps/fnd/upload/webui/xxUploadPG.xml \
-username apps -password -rootdir $JAVA_TOP/xx/oracle/apps/fnd/upload/webui \
-rootPackage /xx/oracle/apps/fnd/upload/webui \
-dbconnection “(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=))(CONNECT_DATA=(SID=)))”

Define a function via Functional Administrator responsibility like below:

image

image

That’s all folks, assign the function to an appropiate menu and users have access to it.
This has been done in 11i but it works exactly the same on R12 environments.

17 thoughts on “Building a generic upload page in OA Framework

  1. Hi robertjungerius,

    Thanks for the post.
    my requirement is to select a file and after pressing Submit it should be inserted in custom table (not in FND_LOBS table)

    can you give me some sample code or pointers to how to implement it ?

    Regards,
    Rani

    1. Hi Rani,

      If you want to use your own table instead of FND_LOBS then you will have to do some additional work in your Jdeveloper project.
      If you use FND_LOBS then EO/VO/AM definition is already supplied by Oracle.
      If you want to use your own table then you need to create an EO and VO (and AM) on your table.
      This is all done with wizards so not really difficult to achieve.

      In your page definition you need to change the AM used by the PageLayoutRN and the View Instance and View Attribute used by the FileName item.
      In the controller behind the page you need to change all references to FndLobsVO to your own VO.

      Hope this helps?

      1. Hi robertjungerius,

        Thanks for the reply. one of my requirement is to store a zip file in a single oracle BLOB column(using a OA framework page.) I have already done that .
        But now I want to unzip the files in the single BLOB column and store each of the individual files in a separate BLOB column in other table.

        Any pointers or suggestions will be highly appreciated

        Regards,
        Rani

    2. Hi Rani,
      I have same requirement.could you plz share your code with me.Its wll be a big help.

      mail—sachinraghava@gmail.com

  2. hi Robertjungerius,

    My name is Saritha and we also have a similar requirement where we upload a spreadsheet from a OA framwork page and load the data into a custom table after certain set of custom validations.All the coding is done in Java controller file and the current issue we have is, we are able to load 500 records successfully but when we try to process more than 500 records the OA frame work page is just stuck in processing state until the page expires.Interesting part is, data is getting loaded into the custom table but the confirmation is not sent on to the page.

    Can you please help?

  3. This is exellent article. Thanks a ton for sharing it.
    What is the best way to pull the file which we uploaded ?

  4. Hello everyone,

    I have created a attachment table in my create page. and its working as expected.

    The problem is;

    1. when my page renders first, i enter some input details of employee and at the end of the page there is a attachment table where i click on attachments and add a file/text and click apply.

    2. After clicking apply button in attachments page, it comes back to my origin page,from where it was initially triggered. Here after coming to my original page, all the field that i have entered before attaching the attachment are cleared off and become null.

    Can anyone help in resolving this issue.

    Thanks,
    Sinan

  5. Hi,

    I have created an messageFileUpload bean in advanced table. The advanced table is based out of custom table which has BLOB domain datatype to store the files.

    When I click on save button in the page, my attachments are getting saved, but the file name in OAF page shows as “VIEW”. But I want to display the filename rather of displaying generic text. I already spent some time searching in dev guide, but I could not find any solution for advanced table.

    Can some one please help me to derive the file name, file type.

  6. hi ROB,

    I am not able to see the java code in the above post.
    can you please reply to my query.
    Thanks,
    Kishan

    1. Hi Kishan,

      I see that the code is indeed very hard to read with the theme I am using.
      Will try to fix it today.
      You can read the code if you’re using IE, when using Chrome it is almost impossible to read the code.

Leave a comment