Wednesday 16 January 2019

Programmatically Inseration in Oracle ADF

Hello everyone
in this post we will learn how we can insert data programmatically

for this example i am using jdeveloper 11.1.2.3.0 and Departments table of HR schema

Steps
1- Create a new application and connect it with oracle HR Schema
2-Create Department and Location view objects and make sure these  objects are Entity base because only Entity base view objects are update able.
3-Create a .jsf page
4-Drag and drop two input texts and a button on .jsf page from component palette
5-Drag and drop LocationView1 on .jsf page as selectOneChoice
6-Dreate a bean and create bindings of input texts and button with bean



in the bean method you need two things
a- Iterators ID and
b-  Row Impl Classes

so for Iterators id  you need to do the following
we need access two iterators in bean
a) DepartmentView Iterator (to insert new row )
b)and LocationView Iterator (to get selected location id )



to access Iterator in bean we need iterator ID and in order to get Iterator ID we need to go
page bindings select the iterator and copy id from property Inspector


and secondly we need Row Impl to access getters and setters

   //4-get current row of location view iterator
       LocationsViewRowImpl locCRow = (LocationsViewRowImpl)locIter.getCurrentRow();
     
   //6-create new row in department view object
        DepartmentsViewRowImpl nrow = (DepartmentsViewRowImpl)vo.createRow();

So to generate RowImpl classes open view object and click on java tab and then click on Edit java option




here is the complete code that we use to insert new department






public class DepartmentInseration {

    private String deptID;
    private String deptName;


    public DepartmentInseration() {
    }

    public String insertNewDepartn() {
        // 1- get bindings
        BindingContainer container=BindingContext.getCurrent().getCurrentBindingsEntry();
        //2-get department view iterator
        DCIteratorBinding deptIter = (DCIteratorBinding)container.get("DepartmentsView1Iterator");
        //3- get location view iterator to get selected location id
        DCIteratorBinding locIter = (DCIteratorBinding)container.get("LocationsView1Iterator");
        //4-get current row of location view iterator
       LocationsViewRowImpl locCRow = (LocationsViewRowImpl)locIter.getCurrentRow();
     
        //5-get department view object from deptIter
        ViewObject vo=deptIter.getViewObject();
        //6-create new row in department view object
        DepartmentsViewRowImpl nrow = (DepartmentsViewRowImpl)vo.createRow();
        //7-set values
        nrow.setDepartmentId(Integer.valueOf(this.getDeptID()));
        nrow.setDepartmentName(this.getDeptName());
        //8-get location id from loaction view current row
        nrow.setLocationId(locCRow.getLocationId());
        vo.insertRow(nrow);
     
        deptIter.getDataControl().commitTransaction();
        //to show popup
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Data saved...."));
     
        return null;
    }

    public void setDeptID(String deptID) {
        this.deptID = deptID;
    }

    public String getDeptID() {
        return deptID;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setLocatonID(String locatonID) {
        this.locatonID = locatonID;
    }

    public String getLocatonID() {
        return locatonID;
    }
}


Please Feel Free To Ask if you Face any Difficulty 
Like and share to help others
Thanks


Date 17-01-2019

5 comments:

  1. Do this hack to drop 2 lbs of fat in 8 hours

    Well over 160 000 men and women are trying a simple and SECRET "water hack" to burn 1-2lbs each night in their sleep.

    It's effective and works all the time.

    This is how to do it yourself:

    1) Grab a drinking glass and fill it half full

    2) Then follow this proven hack

    and you'll be 1-2lbs thinner as soon as tomorrow!

    ReplyDelete
  2. Excellent article and with lots of information. I really learned a lot here. Do share more like this.
    UiPath Training in Chennai
    Blue Prism Online Training
    UiPath Online Training

    ReplyDelete
  3. Perfect post with amazing information and thanks for sharing!!
    Selenium Training in Hyderabad
    Selenium Training in Pune

    ReplyDelete

  4. Great work with lots of knowledgeable information and thanks for sharing!!
    DATA Science Course in Hyderabad
    DATA Science Course in Mumbai

    ReplyDelete

Query to get Business unit (ORGANIZATION_ID) Detail in oracle Fusion

  SELECT HAO.ORGANIZATION_ID AS BUSINESS_UNIT_ID,         HAOT.NAME,         HAO.BUSINESS_GROUP_ID,         HAO.EFFECTIVE_START_DATE,       ...