This blog is helpful for those who are new in Oracle ADF 12c as well as for the professionals. This blog contains the basic and advanced concept of Oracle ADF 12c.

Tuesday 14 March 2017

How to create a Programmatic View Object?

  • Now start creating view object.
         Right click on the model project and select the view object from gallery.
  • Now give the name of view object, Lets say "ProgrameticViewObject" and select the Data source as Programmatic.
         click next.

  • Now star creating the transient attributes for view object by clicking on new button.
         and click next.


  • Now for each attribute specify the constraints.and click next.

  • Now generate a view object class for customization to insert a row Programmatic and click next.

  • If want to work with this view object on view layer then create view object instance on Application module impl xml file.click next.
  • Following structure of view object, and click finish.
  • Programmatic View Object is created.
  • Now to insert row on view object, open ProgrameticViewObjImpl.java class
  • Now to work with view object class , it is important to know the view object lifecycle, for this refer to the post "LifeCycle of View Object".
         a.  first of all create a getter setter of all attributes mentioned on view Object.
             from gallery. 
            select java class and click ok.
        

       b. Specify the name of class and package and click ok. Let say "Employee".


       c. Following class is created.


       d. Now create a getter and setter of viewobject attributes in Employee.java class.

  •    Now open Programmatic view object impl class file.
          Following steps to be perform :-

        a.  view object first call the viewObjectImpl class method                                 executeQueryforCollection() here create a list of data to insert on view object.

        b.  Then next method hasNextForCollection(Object qc) method which check the row               on query collection, if it returns true then move to another method else exit.
              By default their is no row in query collection so we add the blank row on 0 index.

        c.   Then it moves to createRowFromResultSet(Object qc, ResultSet resultSet)                       method , which is responsible to insert row on view object.

     Following Code :- 



import java.sql.ResultSet;

import java.util.ArrayList;

import oracle.jbo.Row;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;

import vo.model.pojo.Employee;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Wed Mar 01 10:54:29 IST 2017
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------

public class ProgrameticViewObjectImpl extends ViewObjectImpl {
    
    ArrayList<Employee> list=new ArrayList<Employee>();
    /**
     * This is the default constructor (do not remove).
     */
    public ProgrameticViewObjectImpl() {
    }

    /**
     * executeQueryForCollection - overridden for custom java data source support.
     */
    @Override
    protected void executeQueryForCollection(Object qc, Object[] params, int noUserParams) {
        //start inserting the value from pojo class in arraylist
        list.add(new Employee(1,"palash",24));
        list.add(new Employee(2,"rajat",25));
        list.add(new Employee(3,"sakshi",23));
        
        setRowPosition(qc,0);
        super.executeQueryForCollection(qc, params, noUserParams);
    }

    /**
     * hasNextForCollection - overridden for custom java data source support.
     */
    @Override
    protected boolean hasNextForCollection(Object qc) {
        boolean bRet = ((Integer)getUserDataForCollection(qc))< list.size();
        return bRet;
    }

    /**
     * createRowFromResultSet - overridden for custom java data source support.
     */
    @Override
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet resultSet) {
        ViewRowImpl value = createNewRowForCollection(qc);
        int fetchSize=(Integer)getUserDataForCollection(qc);
        Employee c= list.get(fetchSize);
        value.setAttribute("EmployeeId", c.getEmpId());
        value.setAttribute("EmployeeName", c.getEmpName());
        value.setAttribute("Age", c.getAge());
        
        setRowPosition(qc, fetchSize+1);
        
        return value;
    }

    /**
     * getQueryHitCount - overridden for custom java data source support.
     */
    @Override
    public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
        long value = super.getQueryHitCount(viewRowSet);
        return value;
    }

    /**
     * getCappedQueryHitCount - overridden for custom java data source support.
     */
    @Override
    public long getCappedQueryHitCount(ViewRowSetImpl viewRowSet, Row[] masterRows, long oldCap, long cap) {
        long value = super.getCappedQueryHitCount(viewRowSet, masterRows, oldCap, cap);
        return value;
    }
    
    private void setRowPosition(Object rowset, int position) {
               if (position == list.size()) {
                    setFetchCompleteForCollection(rowset, true);
        }
        setUserDataForCollection(rowset, new Integer(index));
    }

  • Lets test the view object.
Right click on AppModule file and run the model project.
Read More

Lifecycle of View Object?

When View Object is called , the following methods of ViewObjectImpl are executed in a sequence. 
  • executeQueryForCollection(Object qc, Object[] params, int noUserParams) :-
        This method executes the Database Query in the viewObject and then calls the next method.

       After the execution of executeQueryForCollection
  • hasNextForCollection(Object qc) is called.
         It checks whether the collection has returned a row or not,  If it returns True then the next method of life cycle is called which converts the row to ADF understandable form i.e into ViewObjectRowImpl form.

  • If hasNextForCollection retuns true
         then method createRowFromResultSet(Object qc, ResultSet resultSet) is called.

         if it return false,
         then it comes out from the lifecycle.

  • This goes on until all the rows are covered and there is no rows left in collection. When there are no rows in the collection then the method hasNextForCollection returns false.

  • Then method setFetchCompleteForCollection(java.lang.Object qc,boolean val) is called and it sets the flag for fetch completion. This indicates that the rows from the collection are fetched.
Read More

How to create a Static List View Object?



  • Now start creating view object. 
         Right click on the model project and select the view object from gallery.

  • Now give the name of view object, Lets say "StaticListViewObject" and select the Data source as Static List. and click next.

  • Now create attributes for this view object.

          Lets Say "EmpId, EmpName and Age". These attributes are transient attributes i.e the attribute which is created at view object level.

         For this click on new and create attributes, then click next.



  • Now for each attribute specify the constraints.and make each attribute as updatable to Always. and click next.


  • Insert the rows for this attributes or import csv file if available.and click next



  • If want to work with this view object on view layer then create view object instance on Application module impl xml file, and click next.


  • Following structure of view object, and click finish.


  • Static list View Object is created.

         You will see that view object is available at data control, that can be used to work on view layer.


  • Lets test the view object.

          Right click on AppModule file and run the model project.



Read More

Sunday 12 March 2017

Different Ways to create a Managed Bean of jspx/jsf?

Create a Managed Bean for Page :-



  • Now we will create jspx page.

    Create a jsf/jspx page, for this refer to the post "How to create JSF/JSPX page by using Jdeveloper 12c?", change the page name to "TestPage2".




  • Create a managed bean for TestPage2.jspx.

Approach 1:-

  1. Open faces-config.xml file , go to the overview tab and select managed bean.

    2. Now create a managed bean by clicking on add icon.


     3.  Following popup appears and fill the following fields :-
           
          Bean Name   :-  Name of bean, Lets say "MyBean".
          Class Name   :-  MyClass
          Package         :-  Specify the package to keep this class.
          Scope             :-  Specify the memory scopes, we will select request scope.
          Registration  :- There are 2 options , One is configuration file, this will create a simple java file and other is Annotation, it will create a java class with annotation.
    
      Here we will create configuration file.

      Select the checkbox if we do not have any java class. and click ok.



      4.  You will see the entry of managed bean in faces-config.xml file.


       5.  Now this bean can be accessable on page.


            I have a button on jspx page and now we will bind button component to that bean.



Approach 2 :- 

1.  For this select the design view of TestPage2.jspx and double click on the component.
    Popup will appear.


2.  Mention the following details.

     Managed Bean :- click on new, following popup appears.
     

3.  Specify the following details:-

     Bean Name:- MyBean
     Class Name :- ShowResult
     Specify the Package.
     Scope :- Request.(you can select any scope according to the usage).

    Select the checkbox to generate a java file, and click ok.


4. Now specify the method name in ShowResult class. Let say "resultFromOtherPage", and click ok.



5. Following class is created.

Read More

How to create a custom sql based view object?


  • Now start creating view object.

          Right click on the model project and select the view object from gallery.

  • Now give the name of view object, Lets say "CustomSqlViewObject" and select the Data source as Custom SQL Query. Click next.

  • Now here write the select sql query or use query builder option to write query to fetch the data from db. and click next.


  • Now specify the bind variable for where clause in above query.

         Here we are not using any bind variable and click next.


  • Following db employee table column is mapped to view object attribute. Click next.



  • Here we will create new attribute or delete any attribute from view object, and click next.



  • Now for each attribute specify the constraints.

        Query Column section shows the db employee table column name which is mapped to this view object attribute.
click next.



  • Now following option shown to create java class:-

         View Object Class  :-  this class is used to work programmatically with view object, this class overrides the method of ViewObjectImpl class, that works to perform result on view object.

        View Row Class  :-  This class is used when work with only one row, it implements the ViewRowImpl class.

        Service Data Objects :- If want to use view object as a service, then create this class.
Here we are not doing any customization so unselect all checkbox.

       and click next.



  • If want to work with this view object on view layer then create view object instance on Application module impl xml file.

          click next.


  • Following structure of view object, and click finish.


  • Custom SQL Based View Object is created.

Read More

Social Profiles

Google Plus Email

Popular Posts

palash dabkara . Powered by Blogger.

Followers

Copyright © Oracle ADF 12c (Application Development Framework) Tutorial for Beginners | Powered by Blogger
Design by Palash Dabkara