Friday, July 1, 2016

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 –FileUploadDemo

Automatically a new OA Project will also be created

Project Name -- FileUploadDemo
Default Package -- fileupload.oracle.apps.fnd.fileuploaddemo

2. Create a New Application Module (AM)
Right Click on FileUploadDemo > New > ADF Business Components > Application Module
Name -- FileUploadAM
Package -- fileupload.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 -- fileupload.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
fileupload.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: fileupload.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:\\vishnu";
 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:\\vishnu", 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/PRajkumar/";
 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/PRajkumar", 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);
 }   
}

10. Congratulation you have successfully finished. Run Your page and Test Your Work


a

b

c

d

f

END






Set Default Value for messageTextInput in OAF

1. Create a New OA Workspace and Empty OA Project
File > New > General > Workspace Configured for Oracle Applications
File Name – SetDefaultValDemo

Automatically a new OA Project will also be created

Project Name -- SetDefaultProj
Default Package -- def.oracle.apps.fnd.setdefaultproj

2. Create Application Module AM
Right Click on SetDefaultProj > New > ADF Business Components > Application Module
Name -- SetDefaultAM
Package -- def.oracle.apps.fnd.setdefaultproj.server
Check Application Module Class: SetDefaultAMImpl Generate JavaFile(s)

3. Create a OA components Page
Right click on SetDefaultProj > New > Web Tier > OA Components > Page
Name -- SetDefaultPG
Package -- def.oracle.apps.fnd.setdefaultproj.webui

4. Select SetDefaultPG 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
Region Style
pageLayout
Form Property
True
Auto Footer
True
Window Title
Set Default Value Window Title
Title
Set Default Value Header
AM Definition
def.oracle.apps.fnd.setdefaultproj.SetDefaultAM

6. Create the Second Region
Right click on PageLayoutRN > New > Region

Attribute
Property
ID
MainRN
Region Style
messageComponentLayout

7. Create messageTextInput
MainRN > New > messageTextInput

Attribute
Property
ID
MyTextitemId
Style Property
messageTextInput
Length
20
Maximum Length
50

8. Save Your Work

9. Add a Controller
MainRN > Set New Controller

Package Name -- def.oracle.apps.fnd.setdefaultvaldemo.webui
Class Name -- SetDefaultValCO

10. Edit Your Controller
Add Following Code in processRequest

import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
 super.processRequest(pageContext, webBean);
 String myValue = "Vishnu teja"; 
 OAMessageTextInputBean textBean = (OAMessageTextInputBean)webBean.findChildRecursive("MyTextitemId");
 textBean.setValue(pageContext, myValue);
}


11. Test Your Work


END

Wednesday, June 29, 2016

Execute parameterized PL SQL procedure from OAF page

Let us try to call PL/SQL package from OAF page. We will try to send two interger values to one PL/SQL procedure which will do sum of that numbers and will return back sum of that numbers

1. Create a New OA Workspace and Empty OA Project
File> New > General> Workspace Configured for Oracle Applications
File Name -- ParameterizedProcProj
Project Name – ParameterizedProcDemo
Default Package -- parameter.oracle.apps.fnd.parameterizedprocdemo

2. Create Application Module AM
Right click on ParameterizedProcProj > New > ADF Business Components > Application Module
Name -- ParameterizedProcDemoAM
Package -- parameter.oracle.apps.fnd.parameterizedprocdemo.server
Check Application Module Class: ParameterizedProcDemoAMImpl Generate JavaFile(s)

3. Create a New Page
Right click on ParameterizedProcProj > New > Web Tier > OA Components > Page
Name -- ParameterizedProcDemoPG
Package -- parameter.oracle.apps.fnd.parameterizedprocdemo.webui

4. Select region1 and set the following properties:
ID -- PageLayoutRN
Region Style -- PageLayout
AM Definition --parameter.oracle.apps.fnd.parameterizedprocdemo.server.ParameterizedProcDemoAM
Window Title – Execute Paramterized Procedure Demo Page Window
Title – Execute Paramterized Procedure Demo Page Header
Auto Footer – True

5. Add a New Region MainRN
Select PageLayoutRN right click > New > Region
ID -- MainRN
Region Style – messageComponentLayout

6. Create messageTextInput Items

Create item1
Select MainRN > New > messageTextInput
Set following Properties for Text Item1
ID – item1
Item Style – messageTextInput
Data Type -- Number
Prompt – Text Item1
Maximum Length – 20
Length -- 20

Create item2
Select MainRN > New > messageTextInput
Set following Properties for Text Item1
ID – item2
Item Style – messageTextInput
Data Type -- Number
Prompt – Text Item2
Maximum Length – 20
Length -- 20

7. Create a Submit Button
Right Click on MainRN > New > messageLayout
Select newly created messageLayout right click > New > item
Set Following Properties for newly created item
ID – Sum
Item Style – submitButton
Attribute Set -- /oracle/apps/fnd/attributesets/Buttons/Go
Prompt – Sum

8. Run Your Page UI is ready --


9. Let us create a package and package body which we will call from OAF page
This Package takes three parameters all are number. First two are IN parameters and last is OUT as sum of first two numbers

Package Spec

CREATE OR REPLACE PACKAGE APPS.test_package AUTHID CURRENT_USER
IS
PROCEDURE data_sum
(   item1            IN      NUMBER,
    item2            IN      NUMBER,
    data_sum     OUT  NUMBER
);
END test_package;
/
SHOW ERRORS;
EXIT;

Package Body

CREATE OR REPLACE PACKAGE BODY APPS.test_package 
IS
PROCEDURE data_sum
(   item1          IN    NUMBER,
    item2          IN    NUMBER,
    data_sum  OUT NUMBER
)
IS
BEGIN
 data_sum := item1 + item2;

END data_sum;
END test_package;
/
SHOW ERRORS;
EXIT;

10. Add Following Code in your AMImpl Class (ParameterizedProcDemoAMImpl.java)

import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.server.OADBTransactionImpl;
import oracle.jdbc.OracleCallableStatement;
import java.sql.Types;
import oracle.apps.fnd.framework.OAException; 

...
public String dataSumAction(String item1,String item2)
{ OADBTransaction oadbtransaction = (OADBTransaction)getTransaction(); 
  OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getTransaction();
 String retValues;
 StringBuffer str = new StringBuffer();
 str.append( " BEGIN ");
 str.append( " test_package.data_sum( ");
 str.append( "       item1           => :1, ");
 str.append( "       item2           => :2, "); 
 str.append( "       data_sum    => :3  ");
 str.append( "    ); ");
 str.append( " END; ");
 OracleCallableStatement oraclecallablestatement = 
  (OracleCallableStatement)oadbtransaction.createCallableStatement(str.toString(), 1);
 try{
  oraclecallablestatement.setInt(1,  Integer.parseInt(item1) );
  oraclecallablestatement.setInt(2,  Integer.parseInt(item2) );
  oraclecallablestatement.registerOutParameter(3, Types.VARCHAR);
  oraclecallablestatement.execute(); 
                  
  retValues = oraclecallablestatement.getString(3);
 } 
 catch(Exception e)
 {
  throw OAException.wrapperException(e);
 }
 return retValues;
}

11. Add Controller for Page ParameterizedProcDemoPG Select PageLayoutRN right click Set New Controller
Package Name -- prajkumar.oracle.apps.fnd.parameterizedprocdemo.webui
Class Name -- ParameterizedProcDemoCO
Add Following Code in Controller

import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.OAApplicationModule;
import java.io.Serializable; 

...
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
 super.processFormRequest(pageContext, webBean);
  
 OAApplicationModule am = pageContext.getApplicationModule(webBean);
    
 if (pageContext.getParameter("Sum") != null)        
 {          
  Serializable[] parameters1 = { pageContext.getParameter("item1"),
       pageContext.getParameter("item2"),
      };
                   
  String retVals1 = (String)am.invokeMethod("dataSumAction", parameters1);
  String message = "Sum:  " + retVals1;                   
  throw new OAException(message, OAException.INFORMATION);
 }
}

12. Congratulation you have successfully finished. Run Your ParameterizedProcDemoPG page and Test Your Work
a

b
c

END