Thursday, October 11, 2012

Insert Rows in to ADF View Object Programatically

Following are the use cases pertaining to this topic

1. Insert Rows into ADF View Object Programatically.
2. Insert Rows into a ADF View Object from a ADF Table which is a combination of multiple tables (for example : ADF Table in the jsp page contains mixture of columns from various tables and we need to take only some column data and save it in target ADF VO.

Create a View object from multiple entities (( Assuming you have a View Object SourceVO1 ).Drag and drop the View Object data control on to the page as ADF Table.Create an ADF button at the bottom of the table. Create Action Listener for the button. you must have the target View Object ready to store the values. Since you have created ADF Table on the page the binding section will have the bindings created for the View Object and to access its collection model .For more on bindings section ADF Bindings. Now we need to add the target View Object to the page bindings section.

This part of the section also describes about How to Create Tree Table binding.
Go to the Bindings section of your page. Click Plus icon

 Select tree from the Insert Item window and click ok.

Click Add button as shown . This will list all of the View Objects added to the Application Module

 Choose the desire View Object in which you are going to save the records.

Click at the plus icon and select Add Rule .

This window will bring down all of the attributes that target view object can shuttle the necessary attributes to the righter side and click ok . Now the Target View Object added as Tree binding can be seen under Bindings section.

Now we will write the java code to insert rows. As we have already created an Action Listener for the button,go to the method of that java class and write this code.

//Code to get the bindings for TargetVO :
         DCBindingContainer bindings2 =
        JUCtrlHierBinding obj = (JUCtrlHierBinding)bindings2.findCtrlBinding("ProgrammaticVO1");
        ViewObject targetVO = obj.getViewObject();

   DCBindingContainer bindings =
        DCIteratorBinding empIter =

//SourceVO1Iterator is the iterator under Executables section for the SourceVO1 bindings.

        RowSetIterator roleRSIters = empIter.getRowSetIterator();
        RowSetIterator rs1 = roleRSIters.getRowSet().getViewObject().createRowSetIterator(null);
        NameValuePairs nvp = null;

        while (rs1.hasNext()) {
            Key key =;
            Row r = rs1.getRow(key);           
            nvp = new NameValuePairs();

Getting the View object in MB and performing operations on it is not a good practice.


  1. I think You are breaking the MVC. U should do this all in AM Service Method:) call that method in Bean through binding layer .am I correct?

    1. I had already put a comment about it in the last .'Getting the View object in MB and performing operations on it is not a good practice'