Refreshing a ViewObject on view in JHeadstart

3

Imagine this situation: you have created several tables and a view that queries several columns in these tables. Using BC4J you’d create a ViewObject on the view. The ViewObject contains all the data retrieved from the view, but it won’t show the most recent data if one (or more) of the columns in the tables are updated, i.e. if the output of the view is modified.
On the Oracle Technology Networks Forum I found this solution which I needed to modify a little bit since my view depends on more than one table. Instead of executing the view query when committing changes to a table, I would like to execute the query when the data in the view is displayed.

Of course I could use the provided solution and implement it for each and every ViewObject for the tables that are queried by the view. But when a table is removed from the view, or one is added, I would have to update the implemented changes for those tables. Rather I would have one solution that only needs to be implemented once.
Following the provided solution at OTN, I first modified the Impl java source for my application module. I added this code

public void doQuery() {
  this.getMyView1().executeQuery();
}

Next I published this method through the Client Interface of the Application Module. So far, nothing differs from the solution as provided at OTN.
However, in order to be able to execute the update when loading the ViewObject data in a web page, I need to call the doQuery() method in my application module in the prepareModel method of the JhsDataAction. So, I extended the JhsDataAction class and put this code into it:

public void prepareModel(DataActionContext daContext) throws Exception {
  // before preparing the data model, requery the mailinglist rows
  getMyAppModule(daContext).doQuery();
  // Override of oracle.jheadstart.controller.strutsadf.action.JhsDataAction method
  super.prepareModel(daContext);
}

and everything is working as I want now.

Share.

About Author

3 Comments

  1. Wouter van Reeven on

    Hi Thim,

    I suppose you mean that you have added the method to the ADF action class that is created when dragging and dropping the datapage to the visual editor? Or did you add the method to the jsp page? In either case, can you please provide us with some code so we can see where it goed wrong?

    Thanks, Wouter

  2. This method does not seems to be working or at least not in the way we implemented it.
    We use JDeveloper 1.0.12. We added the method to our datapage were the ViewObject is located but it does not
    seems to refresh our ViewObject. Our doQury() is located in the java class of our ModuleImpl. Were did we
    go wrong?

  3. Leon van Tegelen on

    I see several issues here.
    First of all in case you use a view with Bind parameters, which you specify through the JHeadStart Query Bind Parameters mechanism, these will not be set yet as this is done in the JHSDataAction prepare Model method. So you probably should call super.prepareModel(daContext) before executing the query.
    Secondly I personnaly feel it is beter to call a method on the ApplicationModule via a control action binding on the UImodel of the page.
    But actually I think you should solve it more generically by calling the executeQuery method on all or even selective IteratorBindings in the binding container. No need for the appModule method then and it keeps your code more in line with ADF.

        public void prepareModel(DataActionContext da) throws Exception
      {
        super.prepareModel(da);
        // all iteratorBindings
        ArrayList bindings =   da.getBindingContainer().getIterBindingList();
        for (Iterator it = bindings.iterator(); it.hasNext();)
        {
          ((DCIteratorBinding ) it.next()).executeQuery();
        }
        // specific iteratorBinding
        //da.getBindingContainer().findIteratorBinding("myBinding").executeQuery();
      }
    

    There might be some unexpected situations with specified search criteria and the resultset. For example in a table layout if you create a new row which would not fall within the critera , the transaction would succeed but the row would not be shown as it doesn’t fall in the view criteria