This discussion is archived
1 Reply Latest reply: Feb 8, 2013 1:32 AM by Timo Hahn RSS

error Inserting Rows  to ADF View Object Programatically

adf009 Explorer
Currently Being Moderated
hi am trying to insert rows from another view to another ,following this sample http://howtolearnadf.blogspot.com/2012/10/insert-rows-in-to-adf-view-object.html some how am not able to read my view i got the error in this line ViewObject targetVO = obj.getViewObject(); when i click my add button. am i jedeveloper 11.1.1.6.0 i did create public class UpdAppModuleImpl in my application module i can see the view
my log error is
Caused by: java.lang.NullPointerException
     at OrgDetails.updAddMember(OrgDetails.java:1491)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at com.sun.el.parser.AstValue.invoke(Unknown Source)
     at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
     at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:53)
     at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodBinding(UIXComponentBase.java:1256)
     at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:183)
     at org.apache.myfaces.trinidad.component.UIXCollection.broadcast(UIXCollection.java:148)
     at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:279)
     at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:145)
     at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:402)
     at oracle.adf.view.rich.component.fragment.UIXRegion.broadcast(UIXRegion.java:148)
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.broadcastEvents(LifecycleImpl.java:1018)
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:386)
     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:194)
     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
     ... 38 more
this is my code
    public void updAddMember(ActionEvent actionEvent) {
        // Add event code here...
        //Code to get the bindings for TargetVO :
           
                DCBindingContainer bindings2 =
                   (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
                    
               JUCtrlHierBinding obj = (JUCtrlHierBinding)bindings2.findCtrlBinding("UpdAddedMember1");
               ViewObject targetVO = obj.getViewObject();


          DCBindingContainer bindings =
                   (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
               DCIteratorBinding empIter =
                   bindings.findIteratorBinding("UpdAddedMember1Iterator");

        //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 = rs1.next().getKey();
                   Row r = rs1.getRow(key);           
                  
                   nvp = new NameValuePairs();
                   nvp.setAttribute("Username",r.getAttribute("Username"));
                   nvp.setAttribute("Firstname",r.getAttribute("Firstname"));
                   nvp.setAttribute("Surname",r.getAttribute("Surname"));
                   nvp.setAttribute("Emailaddress",r.getAttribute("Emailaddress"));
                   targetVO.createAndInitRow(nvp);
                }
              
               rs1.closeRowSetIterator();
               targetVO.getApplicationModule().getTransaction().commit();
    }
}
Edited by: adf009 on 2013/02/08 11:17 AM

Edited by: adf009 on 2013/02/08 11:22 AM
  • 1. Re: error Inserting Rows  to ADF View Object Programatically
    Timo Hahn Oracle ACE
    Currently Being Moderated
    adf009, a simple NPE?
    You know how to use a debugger?
    You already know that
                   JUCtrlHierBinding obj = (JUCtrlHierBinding)bindings2.findCtrlBinding("UpdAddedMember1");
    return null. What information do you get by that?
    It telling me that you misspelled the binding name 'UpdAddedMember1' or that it does not exist in the bindings of the page.

    Next you use 'bindings ' and 'bindings2' which are equal. Meanaing you only need one of them.

    What is that code fore:
    while (rs1.hasNext()) {
                       Key key = rs1.next().getKey();
                       Row r = rs1.getRow(key);           
    ...
                      
    you iterate over a row set with the rs1.next() and then jump to the already selected row by setting the row with row.getRow(key);
    while (rs1.hasNext()) {
                       Row r = rs1.next();           
                      
    should do.

    Timo

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points