Get the current node of a tree table in Oracle ADF | Techartifact

Requirement- To get the current current node of tree table and get value of that node.

Solution- we will get the rowKeySet of the treetable.The using findNodeByKeyPath method , we will get the selected node.I already posted to get selected row of tree

RowKeySet selectedRows = treeTable.getSelectedRowKeys();
//use EL to access binding (note that you can do this in Java as well)
JUCtrlHierBinding treeTableBinding = (JUCtrlHierBinding) executeValueExpression("#{bindings.<tree binding name>}");  
//get first entry of selected rows (single selection case)
JUCtrlHierNodeBinding node =  treeTableBinding .findNodeByKeyPath((List)selectedRows .iterator().next());
... do the work with the node here ...

private Object executeValueExpression(String valueExpression){
      FacesContext fctx = FacesContext.getCurrentInstance();
      ELContext elctx = fctx.getELContext();
      Application app = fctx.getApplication();
      ExpressionFactory exprFactory = app.getExpressionFactory();
      ValueExpression valueExpr = exprFactory.createValueExpression(
                                elctx,
                                valueExpression,
                                Object.class);
       return valueExpr.getValue(elctx);
      }

Happy coding with Vinay Kumar in Techartifact

How to perform addition for attribute of Number type in expression language

When adding two attributes of oracle.jbo.domain.Number type in Expression Language like EmpSal and EmpBonus as below  :

#{bindings.bindings.EmpSal.inputValue + bindings.EmpBonus.inputValue}

or adding number 1000 to EmpSal as  :

#{bindings.bindings.EmpSal.inputValue + 1000}

You may get below exception :

Unexpected exception caught: java.util.MissingResourceException, msg=Can’t find resource for bundle java.util.PropertyResourceBundle, key el.convert

To Eliminate this Exception, Add EmpSal and EmpBonus as below :

#{bindings.EmpSal.inputValue.value + bindings.EmpBonus.inputValue.value}

Add ‘value’ to inputValue to remove the exception.

Happy learning in TechArtifact. 🙂

How to check ifdirty (is modified) for View Object?

Requirement – Checking if data modified in viewobject ADF

Solution-You can use isDirty() method provided by API to get status

 DCBindingContainer bind =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        JUCtrlHierBinding object = (JUCtrlHierBinding)bind.findCtrlBinding("DepartmentVO1"); // or get ViewObject form Iterator in ADFUtils.
        ViewObject deptVo = object.getViewObject(); 
        Boolean b = deptVo.getApplicationModule().getTransaction().isDirty();This gives Boolean value of True/False. 

another way

DCBindingContainer dcBindingContainer=(DCBindingContainer)
BindingContext.getCurrent().getCurrentBindingsEntry();
if(dcBindingContainer.getDataControl().isTransactionModified()){
//Code goes here...
}

few more use case i found on internet i.e http://oracleadfhowto.blogspot.de/2012/03/iterator-uncommitted-data-availability.html, so thought of sharing that as well –

1. If you are using iterator based UI component like table:
Expression #{row.row.entities[0].entityState} will return state viz. (0 – New, Modified – 2, Unmodified – 1, Initialized – -1 where row refers to the table node and row.row is the instance of row in the iterator/table.

The following expression also notify that there is dirty data available –

-> #{!bindings.EmployeesView1Iterator.dataControl.TransactionDirty}   // this statment will notify that there is uncommitted or unsaved data in the iterator
-> #{!bindings.Commit.enabled}
-> #{!controllerContext.currentRootViewPort.dataDirty}
-> #{!controllerContext.currentViewPort.dataDirty} 

Happy ADF learning with Vinay in techartifact….