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…
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.
Click next twice to get to step 3…
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.
Leave the package name as is…
Press next and press finish on page 2.
Now we can import the files you copied from the server to myclasses.
Find your myclasses directory and goto myclasses/oracle/apps/fnd/server, there should be a server.xml file over there which we will import.
You can get following message, answer with Yes.
Your project should now look like below:
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.
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
Add an item to the pageLayout region with Item Style messageFileUpload.
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
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:
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.
Add a controller to the pageLayout region.
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:
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:
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.