Upload File in OAF

Introduction

Today we will see How we can upload any file in OAF and the same file will get stored in a record in a Database table. ThereforeA�to achieve this, the following things are required:

  1. Database Table column need to be of BLOB datatype. (Binary Large OBject).
  2. MessageFileUpload Item need to be used in OA Page.

Upload File in OAF

To continue with our project ( all previous blogs need to be followed sequentially), we will upload Employee’s resume and store it in the Database along with the Resume Name (i.e File name being uploaded). The actual file will be stored in the FILE_CONTENTA�column and the resume or file name will be stored in FILE_NAMEA�column ofA�XXRD_EMP_TAB. Please refer the table script for creating table XXRD_EMP_TAB. Let’s have a look at the implementation of File Upload functionality in OAF:

  1. Right Click on CreateRN (messageComponentLayout), Select Item Style messageFileUpload.
  2. Describe the following properties:
    Properties Value
    ID EmpResume (any valid name)
    Item Style messageFileUpload
    Data Type BLOB
    View Instance XXRDEmpVO1
    View Attribute FileContent
    Prompt Resume

    The screenshot of the same is attached here:file_upload_OAF This will store the file in FILE_CONTENT column in XXRD_EMP_TAB column.

  3. Now to get the name of the file being uploaded, we have to use OAF provided predefined Parameter Name “UPLOAD_FILE_NAME”. In addition to that if we have to get the MIME type of the file, “UPLOAD_FILE_MIME_TYPE” is used. So the below code snippet needs to be added in the processFormRequest() method in the Controller code:String fileName = pageContext.getParameter(“UPLOAD_FILE_NAME”); // Gives File Name of the uploaded file
    String fileMimeType = pageContext.getParameter(“UPLOAD_FILE_MIME_TYPE”); // Gives MIME Type of the uploaded file.

Invoke AM Method with Parameters

  1. Having derived the file name at step 3, we have to set the same value to the fileName attribute of XXRDEmpVO. For this, a method setFileName() has been added in XXRDRootAMImpl. Here is the code snippet:public void setFileName(String fileName){
    XXRDEmpVOImpl empVO = getXXRDEmpVO1();
    empVO.getCurrentRow().setAttribute(“FileName”,fileName);
    }
    So basically setFileName() takes fileName as parameter being sent from Controller and sets the FileName attribute for the current Row of XXRDEmpVO1 instance.
  2. Now from Controller, derived fileName value will be sent to setFileName() AM method. Let’s see how?Serializable params[] = {fileName};
    Class paramClass[] = {fileName.getClass()};// Invoke AM method “setFileName” with paramters
    rootAM.invokeMethod(“setFileName”,params,paramClass);
    In order to pass any parameter to any method of AM, those parameters need to be serialized and then sent. To do this, a Serializable array for the parameters and class of those parameters have been sent during method invocation along with the method name to be invoked. Here is the output of our work:file_upload_output_OAF

This is how we upload File in Database table column through OAF. In due course, we also saw how to pass parameters to AM method from Controller. In our next article, we will see how to show message in OAF Page through Exception.

Leave a Reply

Your email address will not be published. Required fields are marked *

Show my latest post here