0% found this document useful (0 votes)
654 views5 pages

OAF Page To Upload Files Into Server From Local Machine

This document describes how to create an OAF page to upload files from a local machine to a server. It involves: 1. Creating a new workspace and project 2. Adding an application module (AM) 3. Creating a new page with a file upload item and submit button 4. Writing code in the page controller to upload the file to the specified server path when the button is clicked.

Uploaded by

Ravi Birhman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
654 views5 pages

OAF Page To Upload Files Into Server From Local Machine

This document describes how to create an OAF page to upload files from a local machine to a server. It involves: 1. Creating a new workspace and project 2. Adding an application module (AM) 3. Creating a new page with a file upload item and submit button 4. Writing code in the page controller to upload the file to the specified server path when the button is clicked.

Uploaded by

Ravi Birhman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

OAF Page to Upload Files into Server from local Machine

OAF Page to Upload Files into Server from local Machine


1. Create a New Workspace and Project
File > New > General > Workspace Configured for Oracle Applications
File Name MahiFileUploadDemo
Automatically a new OA Project will also be created
Project Name -- FileUploadDemo
Default Package -- Mahi.oracle.apps.fnd.fileuploaddemo
2. Create a New Application Module (AM)
Right Click on FileUploadDemo > New > ADF Business Components > Application Module
Name -- FileUploadAM
Package -- Mahi.oracle.apps.fnd.fileuploaddemo.server
Check Application Module Class: FileUploadAMImpl Generate JavaFile(s)
3. Create a New Page
Right click on FileUploadDemo > New > Web Tier > OA Components > Page
Name -- FileUploadPG
Package -- Mahi.oracle.apps.fnd.fileuploaddemo.webui
4. Select the FileUploadPG and go to the strcuture pane where a default region has been created

5. Select region1 and set the following properties -Attribute

Property

ID

PageLayoutRN

AM Definition

Mahi.oracle.apps.fnd.fileuploaddemo.server.FileUploadAM

Window Title

Uploading File into Server from Local Machine Demo Window

Title

Uploading File into Server from Local Machine Demo

6. Create messageComponentLayout Region Under Page Layout Region


Right click PageLayoutRN > New > Region
Attribute

Property

ID

MainRN

Item Style

messageComponentLayout

7. Create a New Item messageFileUpload Bean under MainRN


Right click on MainRN > New > messageFileUpload
Set Following Properties for New Item -Attribute

Property

ID

MessageFileUpload

Item Style

messageFileUpload

8. Create a New Item Submit Button Bean under MainRN


Right click on MainRN > New > messageLayout
Set Following Properties for messageLayout -Attribute

Property

ID

ButtonLayout

Right Click on ButtonLayout > New > Item

Attribute

Property

ID

Submit

Item Style

submitButton

Attribute Set

/oracle/apps/fnd/attributesets/Buttons/Go

9. Create Controller for page FileUploadPG


Right Click on PageLayoutRN > Set New Controller
Package Name: Mahi.oracle.apps.fnd.fileuploaddemo.webui
Class Name: FileUploadCO
Write Following Code in FileUploadCO processFormRequest
import oracle.cabo.ui.data.DataObject;
import java.io.FileOutputStream;
import java.io.InputStream;
import oracle.jbo.domain.BlobDomain;
import java.io.File;
import oracle.apps.fnd.framework.OAException;
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{ super.processFormRequest(pageContext, webBean);
if(pageContext.getParameter("Submit")!=null)
{
upLoadFile(pageContext,webBean);
}
}
CODE #1 -- If Page has not deployed at instance, testing at Local Machine, use following Code
public void upLoadFile(OAPageContext pageContext,OAWebBean webBean)
{ String filePath = "D:\\Mahi";
System.out.println("Default File Path---->"+filePath);
String fileUrl = null;
try
{
DataObject fileUploadData = pageContext.getNamedDataObject("MessageFileUpload");

//FileUploading is my MessageFileUpload Bean Id


if(fileUploadData!=null)
{
String uFileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
String contentType = (String) fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
System.out.println("User File Name---->"+uFileName);
FileOutputStream output = null;
InputStream input = null;
BlobDomain uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, uFileName);
System.out.println("uploadedByteStream---->"+uploadedByteStream);
File file = new File("D:\\Mahi", uFileName);
System.out.println("File output---->"+file);
output = new FileOutputStream(file);
System.out.println("output----->"+output);
input = uploadedByteStream.getInputStream();
System.out.println("input---->"+input);
byte abyte0[] = new byte[0x19000];
int i;
while((i = input.read(abyte0)) > 0)
output.write(abyte0, 0, i);
output.close();
input.close();
}
}
catch(Exception ex)
{
throw new OAException(ex.getMessage(), OAException.ERROR);
}
}

CODE #2 -- If Page has been Deployed at Instance, Use Following Code


public void upLoadFile(OAPageContext pageContext,OAWebBean webBean)
{ String filePath = "/u01/app/apnac03r12/Mahi/";
System.out.println("Default File Path---->"+filePath);

String fileUrl = null;


try
{
DataObject fileUploadData = pageContext.getNamedDataObject("MessageFileUpload");
//FileUploading is my MessageFileUpload Bean Id
if(fileUploadData!=null)
{
String uFileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
String contentType = (String) fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
System.out.println("User File Name---->"+uFileName);
FileOutputStream output = null;
InputStream input = null;
BlobDomain uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, uFileName);
System.out.println("uploadedByteStream---->"+uploadedByteStream);
File file = new File("/u01/app/apnac03r12/Mahi", uFileName);
System.out.println("File output---->"+file);
output = new FileOutputStream(file);
System.out.println("output----->"+output);
input = uploadedByteStream.getInputStream();
System.out.println("input---->"+input);
byte abyte0[] = new byte[0x19000];
int i;
while((i = input.read(abyte0)) > 0)
output.write(abyte0, 0, i);
output.close();
input.close();
}
}
catch(Exception ex)
{
throw new OAException(ex.getMessage(), OAException.ERROR);
}
}

You might also like