Refreshing child node in the tree in ADF

Requirement – To refresh the tree child node. Executing the top level view object instance alone is not enough. This is because when you expand a parent node, if the
framework identifies any existing query collection for the row filter supplied by the parent row, the existing query collection cache will be reused for displaying
child nodes. To refresh specific child nodes, you will have to find the appropriate child row set and refresh it by calling the executeQuery() method.

For example. We have displaying country in tree node. In Child node we are displaying the states. For we will taking out the country id and fetch the row on basis of countryID and get the rowset
and call executeQuery() method and it will refresh the child node as well.

Below is the code.

public void refreshChildStates(Number CountryId) {
//Gets the VO used for parent node
ViewObjectImpl vo = getCountry();
//Read the row using Key CountryId
Row[] countryRow= vo.findByKey(new Key(new Object[] { CountryId}), 1);
RowSet childRows =
(RowSet)stateRow[0].getAttribute("States")';
childRows.executeQuery();
}

Happy coding with Techartifact…

Changing the WHERE clause or VO Query at runtime in Oracle ADF

Requirement- To change the WHERE clause of a query at run time:

Create a String containing the new WHERE clause. Do not include the word “WHERE”. If you do want to remove the WHERE clause entirely, use null. For example, either of the following could be appropriate definitions:

Pass this string into setWhereClause(). For example, if OrdVO is a variable containing the view object instance to be changed, you would call:

String whereClause = “ORDER_TOTAL > 500”;
String whereClause = null;
ordVO.setWhereClause(whereClause);

You can write this method in AmImpl.Java.For example

    public void executeSearchInstanceNoExp(String instanceNo) {
    String whereClause="instance_status = 'EXPIRED'";
    ViewObjectImpl searchVO = this.getEmployeeVo(); //relaventVO
    searchVO.setWhereClause(whereClause);
    searchVO.executeQuery(); //executeVO with Criteria

    }

you can add ORDER BY clauses of a query at runtime by calling setOrderByClause() on the view object.

String orderByClause = "ORDER_TOTAL";
ordVO.setOrderByClause(orderByClause);

Change the VO query at runtime or changing the Table or view at runtime

createViewObjectFromQueryStmt is used to change the query .You can write this method in AmImpl.Java

    public void executeSearchVoExp() {
       String sqlStatement= "select * from EMP";
        ViewObject dynamicVO = this.findViewObject("SearchByCustomerVo1");  
        dynamicVO.remove();  
        dynamicVO = this.createViewObjectFromQueryStmt("SearchByCustomerVo1", sqlStatement);  
        dynamicVO.executeQuery(); //executeVO with Criteria

    }