Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

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.

Friday, February 5, 2010

JDeveloper, and Weblogic:Accessing Detailed Views from Master One Using Java

One of the most addressable issues in Oracle ADF Application Development is how to access your business model components through Java method call. Accessing the parent view that requires a bind variable and attaching it to a page doesn't mean that the details views related to master one at data model level will execute with same bind variable.

In this post we will address the problem of how to call a master view with bind variable set through Java call ? and at the same time to fetish data from detail views ?

First of all make sure that your data model is built to reflect master detail relation. A view link between Master and Detail should be created at first and added to Data Model, like simple two key join in a select statement:

As you note a country-City relation ship exists, in which you must get country to get its cities.
The country view has a bind variable set at run-time through expression language and called through execute with params method call. This what happened at normal page flow navigation. But, in our case we want to set the bind variable using Java code and then looping thourgh to get the detailed cities.

Tuesday, February 2, 2010

JDeveloper, Weblogic and ADF: Security in Oracle ADF and Session invalidate

In enterprise applications that require user authentication, a user can't navigate back to a cached page. When developing applications using JDeveloper11g ADF, I encountered two problems.

First, how to kill a user session when clicking logout button, as explained below:
In ADF, you might use SessionScope to create variables or beans that can be carried out during the life cycle of a user session. Destroying the session bean or setting a session variable to null doesn't mean that the session is killed, to kill a session you have to:

1- Add a method call to logout button Action can be in the managed or backing bean and name it logout_action();

2- The code is used to invalidate the user session then redirect the page to your login screen displayed below:

        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ectx = fc.getExternalContext();      
        HttpSession session = (HttpSession)ectx.getSession(false);
        try {
            session.invalidate();          
            ectx.redirect("../loginpage");
            fc.responseComplete();
        } catch (Exception exp) {
            ectx.redirect("../loginpage");
            fc.responseComplete();
        }

* note if you are using a bounded task flow and your loging screen exists in unbounded task flow located one level up then consider navigating through floders using (..) till login screen location.