Wednesday, 22 April 2015

OAF: Transient Attributes not getting populated in Extended VO

Recently I saw one question in OTN Forum on this topic "Transient Attributes not getting populated when we do VO Substitution". So I thought posting the solution here.


Scenario:

Standard VO has some transient attributes which gets populated by overriding the getter methods in the VORowmpl. When we extend this VO for adding some additional attributes, everything works except the original transient attributes. Those attributes are coming as null.


The reason is, when the extended VORowImpl is getting generated by the Jdeveloper, it will not call the super method (which is already overridden). So you need to modify the getter method of the Transient attribute in the extended VO to call the getter method in the Standard VO using super.


Standard VORowImpl getter method will be something like this :
 public String getAttribute1(){  
      return "Calculated Value";  
 }  

Generated getter method in the extended VORowImpl will be like this:
 public String getAttribute1() {  
      return (String) getAttributeInternal("Attribute1");  
 }  

To fix this, modify the getter method of the extended VORowImpl like this:
 public String getAttribute1() {  
      //return (String) getAttributeInternal("Attribute1");  
      return super.getAttribute1();
 }  

Feel free to point out if anything is missing/wrong in this blog.

Monday, 20 April 2015

ADF: How to execute the ViewObject with a ViewCriteria on the PageLoad in ADF Web Application

This post explain how to restrict the ViewObject Query with a ViewCriteria on the page Load.

When the page is created with a Bounded Task Flow
  • Create a custom method in the Application Module.
  • Expose the method as a Client Interface.
  • Now there are 2 ways which you can invoke this method when the page loads.

  1. Drag the AM method from the Data Control into the BTF and add that as the Default Activity.
  2. Make a bean method as the Default Activity and then call the AM method from that. This is bit tricky. What you need to do is drag the AM method as a method to the BTF. This will created the needed bindings in the BTF. Then change the method property to map to the bean method. Then you can access the AM method from the Bean method. [Thanks to Timo Hahn from OTN Forum]


  • Sample code  to call the AM method from the Bean method.
  • Output

When the page is created without a Bounded Task Flow
  • Create a method in the managed Bean.
  • Call this method in PhaseListener. Need to be careful when you write code in the PhaseListener as this gets called in several times in the Page LifeCycle.

  • Output
Sample application built using Jdev 12.1.3 can be downloaded from here.

Reference : An Epic Question "How to call a method when the page loads"
Feel free to point out if anything is missing/wrong in this blog.

Thursday, 9 April 2015

Links for Developer Guides

Sometimes I spend 4-5 minutes to find out the corresponding Developer guides when am working on different projects (especially on client machines), whether it is OAF or ADF or MWA/MSCA or PL/SQL or Java. So thought of adding this to my blogs, so that whatever I have used, I can just have an index for those.


             Section 1.6.3.5: Deploying OA Framework Business Logic Extensions
Application Express (APEX)
Mobile Supply Chain ApplicationFramework (MSCA / MWA)

Some links which I felt very useful:


Tuesday, 7 April 2015

PL/SQL: Sample code to insert BLOB into Oracle database table.

This post explains how to insert a blob object into database table programmatically.
  • Create a folder/directory (ex:- C:\test )manually in the file system.
  • Create a directory object in the database by connecting as SYSDBA and grant the access to custom schema(ex:- HR)
 CONN / AS SYSDBA;  
 CREATE OR REPLACE DIRECTORY images AS 'C:\test';  
 GRANT READ, WRITE ON DIRECTORY images TO HR;
  • Create the table as below in the custom schema (ex:-HR)
 CREATE TABLE IMAGE_STORE  
  (  
   IMAGE_ID NUMBER ,  
   FILE_NAME VARCHAR2(200 BYTE) ,  
   IMAGE BLOB,  
   MIME_TYPE VARCHAR2(100 BYTE),  
   CONSTRAINT IMAGE_STORE_PK PRIMARY KEY (IMAGE_ID)  
  );
  • Copy a test file (Test_File.pdf) into the directory ('C:\test') mentioned in the above script.
  • Now connect to the custom schema (HR) and execute the below code
 DECLARE  
  src_lob BFILE := BFILENAME('IMAGES', 'Test_File.pdf');  
  dest_lob BLOB;  
 BEGIN  
  INSERT INTO image_store VALUES (1,'Test_File.pdf', EMPTY_BLOB(), 'application/pdf')  
  RETURNING image INTO dest_lob;  
  DBMS_LOB.OPEN(src_lob, DBMS_LOB.LOB_READONLY);  
  DBMS_LOB.LoadFromFile(   
              DEST_LOB => dest_lob,  
              SRC_LOB => src_lob,  
              AMOUNT  => DBMS_LOB.GETLENGTH(src_lob) );  
  DBMS_LOB.CLOSE(src_lob);  
  COMMIT;  
 END;  
 /  
Feel free to point out if anything is missing/wrong in this blog.

Monday, 6 April 2015

ADF: How to download a file from database in ADF Web Application

This post explains how to download a file stored in the database in a Blob/Clob column from a ADF Web Application.
The data from the table will be displayed in a table format and one column will have a image icon to download the corresponding file.

The table structure used in this sample application :
 CREATE TABLE IMAGE_STORE  
  (  
   IMAGE_ID NUMBER ,  
   FILE_NAME VARCHAR2(200 BYTE) ,  
   IMAGE BLOB,  
   MIME_TYPE VARCHAR2(100 BYTE),  
   CONSTRAINT IMAGE_STORE_PK PRIMARY KEY (IMAGE_ID)  
  );  
Sample code to insert a blob into table is available : Johny's Tips: PL/SQL: Sample code to insert BLOB into Oracle database table.
  • Create the Model Project and create the ViewObject and add that to the Application Module.
  • Create a page and add the DataControl as a table to the project.
  • Create a Attribute Binding for the Clob/Blob object. 
    [Thanks to Cvele_new_account from OTN Forum]

  • Add a link component as one column and add a fileDownloadActionListener.
             Note:- If you don't specify the fileName, the file will be written to the browser.
  • Create a Managed Bean and write the code as below for Blob Object.
   public void downloadBlobFile(FacesContext facesContext, OutputStream outputStream)  
   {  
     BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();  
     AttributeBinding attr = (AttributeBinding) bindings.getControlBinding("Image");  
     if (attr != null)  
     {  
       BlobDomain blob = (BlobDomain) attr.getInputValue();  
       try  
       {  // copy the data from the blobDomain to the output stream   
         IOUtils.copy(blob.getInputStream(), outputStream);  
         blob.closeInputStream();  
         outputStream.flush();  
       }  
       catch (IOException e)  
       {  
         // handle errors  
         e.printStackTrace();  
         FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");  
         FacesContext.getCurrentInstance().addMessage(null, msg);  
       }  
     }  
   }  
  • Create a Managed Bean and write the code as below for Clob Object.
   public void downloadClobFile(FacesContext facesContext, OutputStream outputStream)  
   {  
     BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();  
     AttributeBinding attr = (AttributeBinding) bindings.getControlBinding("Image");  
     if (attr != null)  
     {  
       ClobDomain clob = (ClobDomain) attr.getInputValue();  
       try  
       {  // copy the data from the clobDomain to the output stream   
         IOUtils.copy(clob.getCharacterStream(), outputStream);  
         clob.closeInputStream();  
         outputStream.flush();  
       }  
       catch (IOException e)  
       {  
         // handle errors  
         e.printStackTrace();  
         FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");  
         FacesContext.getCurrentInstance().addMessage(null, msg);  
       }  
     }  
   }  
Note:- IOUtils (org.apache.commons.io.IOUtils) is a class from the Apache Commons IO Package (http://www.apache.org/). Please download it directly from http://projects.apache.org/projects/commons_io.html


Sample application built using Jdev 12.1.3 can be downloaded from here.

Reference: Timo Hahn's: JDev11.1.2.1.0: Handling images/files in ADF (Part 2)

Feel free to point out if anything is missing/wrong in this blog.

Wednesday, 1 April 2015

OAF: Sample code to call PL/SQL Function from OA Framework

Please find below sample code to call PL/SQL function from OA Framework page.
 import oracle.apps.fnd.framework.server.OADBTransaction;  
 import oracle.jdbc.driver.OracleTypes;  
 import oracle.jdbc.OracleCallableStatement;  
 public String callFunction( String id)  
 {  
      String status = null;
      OADBTransaction oadbtransaction = getOADBTransaction();  
      OracleCallableStatement oraclecallablestatement = null;  
      Object obj = null;  
      String sqlString = "BEGIN :1:=xx_pkg.xx_func( p_id => :2 ); END;";  
      try  
      {  
           oraclecallablestatement = (OracleCallableStatement)oadbtransaction.createCallableStatement(sqlString , 1);  
           oraclecallablestatement.registerOutParameter(1, OracleTypes.VARCHAR, 0, 10);  
           oraclecallablestatement.setString(2, id);  
           oraclecallablestatement.executeQuery();  
           status = String.valueOf(oraclecallablestatement.getString(1));  
      }  
      catch(Exception exception1)  
      {  
           throw OAException.wrapperException(exception1);  
      }  
      finally  
      {  
           try  
           {  
                oraclecallablestatement.close();  
           }  
           catch(Exception exception2)  
           {  
                throw OAException.wrapperException(exception2);  
           }  
      }  
      return status ;  
 }  
Feel free to point out if anything is missing/wrong in this blog.