Saturday, October 6, 2012

Programmatic approach to insert record in ADF


Best approach to create or insert a row in the table which requires some custom logic to be built which needs to be called and after processing the data is to have the method which inserts/creates the row in the Application Module implementation class. Then create the data control of the method. Then bind the method to the view , where backing bean would call this create method.

Below given code is the one,which will be the method in AppModuleImpl.java. To see this class you will have to go to the AppModule.xml in Overview mode  and then click on the Java tab. Click on the edit icon which looks like a pencil and then generate the classes.



public String create(Integer a, Integer b, Integer c,
                              java.util.Date d) {
    String result="Create Complete!";
    AttributeList at = new AttributeListImpl();
    at.setAttribute("A", a);
    at.setAttribute("B", b);
    at.setAttribute("C", c);
    at.setAttribute("D", d);
    Row row = getCase1View1().createAndInitRow(at);

    at.setAttribute("A", a);
    at.setAttribute("B", b);
    at.setAttribute("C", c);
    at.setAttribute("D", d);
    this.getEmp1View1().getDBTransaction().commit();
   
      return "created";
     
  }


To expose the method as a data control, you need to click on the Client Interface  edit icon and then select the method and save. This process will create a client interface java class which will expose the method as a data control. Which can then be binded to the view.


Then the below given code can be used in the managed bean to call the method binded.

         DCBindingContainer bindings =
        (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();

        OperationBinding op = (OperationBinding)bindings.getOperationBinding("create");
        op.getParamsMap().put("a", 1);
        op.getParamsMap().put("b", 1);
        op.getParamsMap().put("c", 1);
        op.getParamsMap().put("d", new Date());
        op.execute();


No comments:

Post a Comment