Sunday, March 21, 2010

Inserting Data in hidden detailed table after inserting in Master one

When working with a friend trying to insert data in a detailed table (without dropping the detailed table in a page view associated with its master table), and getting some of the detailed table column values from the same data inserted in the master table, we came across to use the following code:


public String insert_master_detail() {

        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
                                         bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        //Perform a commit on the master table binding on page view
      
        if (operationBinding.getErrors().isEmpty()) {
        //if transaction succeeded then continue adding data to detail
          table


        String amDeff = "model.AppModule";
        String config = "AppModuleLocal";
        ApplicationModule am =  
               Configuration.createRootApplicationModule(amDeff, config);
        ViewObject vo = am.findViewObject("DetailTabke1");
        //connect to the detail view using the application module 
      
       BindingContainer bc = 
          BindingContext.getCurrent().getCurrentBindingsEntry();
       //get the current page bindings
      
    
        JUCtrlAttrsBinding Code = 
                              (JUCtrlAttrsBinding)bc.get("Code");        
        
        JUCtrlAttrsBinding Name = 
                                  (JUCtrlAttrsBinding)bc.get("Name");  
       //get list of data added to the master table that will be add to 
        the detailed table
      
        NameValuePairs pairs = new NameValuePairs();
        pairs.setAttribute("Code",
                       Code.getAttributeValue().toString());
        Number n=new Number(1);
        pairs.setAttribute("No", n);
        pairs.setAttribute("Name",
                      Name.getAttributeValue().toString());
        pairs.setAttribute("Status", "00020");
        pairs.setAttribute("Typee", "051");
        pairs.setAttribute("StartDate", "1430/01/01");
        pairs.setAttribute("EndDate", "1430/01/01");
        
        Row ActivityTaskRow = vo.createAndInitRow(pairs);
        vo.insertRow(ActivityTaskRow);
        //create a Name value attribute and calling createAndInitRow
          with name value attributes for detailed table that will be 
          used to insert row in table
    
        am.getTransaction().commit();
        //commit the transaction and then release the connection


        Configuration.releaseRootApplicationModule(am,true);
        }
        return null;
 }


This code is added as an action to submit button and should be called after creating a new row in the master table.

2 comments:

  1. You shouldn't be creating a new application module - instead you should be using the existing one that is already out there.
    See the section:
    9.10.3 How to Access an Application Module Client Interface in a Fusion Web Application
    http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcservices.htm#sthref918

    And you might want to wrap up your update as an AM Service method instead of coding it on the UI layer.

    ReplyDelete
  2. Thanks for the advise, regarding application module you are right and you can get it for the binding container it self.

    This code was on the fly as a fast solution and it did the work!

    ReplyDelete