Sunday, January 5, 2014

Uploading File to server from OAF Page

Uploading Flat File to server from OAF Page


Now we are going to learn about how to load the flat files to server from oaf page.
For uploading the files in OAF we have the item called “MessageFileUpload” using this we can load the files.

Steps are as follows.

Step1: - Create the workspace and project.

Step2: - Create the application module.

Step3: - Create the page and attach the application module to the page and in properties
              Give the window title and title.

Step4:- Create one region with style “message component layout” under page layout region
And create two items under message component layout one with style “messageFileUpload”        and second is a submit button.

The structure of the page is like below.



If u want any spaces between the items then create the item with style spacer.




Step5: - Create the controller for pageLayoutRegion.

            Write the following code in the processFormRequest method of a controller
             
             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);  

    TFitFileLoaderAMImpl am = TFitFileLoaderAMImpl)pageContext.getRootApplicationModule();

if(pageContext.getParameter("Submit")!=null)
            {
                  am.uploadFile(pageContext,webBean);    
             }
 }

           Create a method called uploadFile in AMImpl.java

          Otherwise you can create the method in controller only.
          If you create method in controller then in the above code do not initialize Application module and                   while calling the method use the bellow syntax.
          uploadFile(pageContext,webBean);

  


        import java.io.File;
        import java.io.FileOutputStream;
        import java.io.InputStream;
        import java.sql.Types;
        import oracle.apps.fnd.framework.OAException;
        import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
        import oracle.apps.fnd.framework.server.OADBTransaction;
        import oracle.apps.fnd.framework.server.OADBTransactionImpl;
        import oracle.apps.fnd.framework.webui.OAPageContext;
        import oracle.apps.fnd.framework.webui.beans.OAWebBean;
        import oracle.cabo.ui.data.DataObject;
        import oracle.jbo.domain.BlobDomain;
        import oracle.jdbc.OracleCallableStatement;

         public void uploadFile (OAPageContext pageContext,OAWebBean webBean)
        {
 String filePath = “/Software/apps/apps_st/appl/xx/msd/tfit/”;
  
 String fileUrl = null;
            
try
            {
           
  DataObject fileUploadData =  pageContext.getNamedDataObject("Give the id of message file                                                                                                                            upload item");

                  if(fileUploadData!=null)
                  {
                    String FileName = (String)fileUploadData.selectValue(null, 
"UPLOAD_FILE_NAME");   
             String contentType = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");   
                    FileOutputStream output = null;
                    InputStream input = null;
BlobDomain uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, FileName); 
                              
          File file = new File(“/Software/apps/apps_st/appl/xx/msd/tfit”, FileName);  
          output = new FileOutputStream(file);
                       input = uploadedByteStream.getInputStream();
                       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);
            }    
        }

Step6: - Register the page in server and run the page.

            
     


            

         Brows the file and click on submit button it will store in server.