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

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

We will be writing selectionListener for that tree in managed bean.first we invoke the default tree selection listener with the expression
#{bindings.Departments.treeModel.makeCurrent}. In order to do this, we use a helper method called invokeMethodExpression(). Then, we obtain the currently selected node from the tree by calling getRowData() on the oracle.adf.view.rich.component.rich.data.RichTree component (obtained earlier from the selection event).

    public void treeRowSelectionlistener(SelectionEvent selectionEvent) {
       
        invokeMethodExpression("#{bindings.checklistStructureVO1.treeModel.makeCurrent}", Object.class, SelectionEvent.class, selectionEvent);
        
        RichTree tree = (RichTree)selectionEvent.getSource(); // get the tree component from the event
           TreeModel model = (TreeModel)tree.getValue();    
           //get selected nodes
           RowKeySet rowKeySet = selectionEvent.getAddedSet();
        Iterator rksIterator = rowKeySet.iterator();
        //Validating for single select only. Need to check for multiselect
        while (rksIterator.hasNext()) {
            List key = (List)rksIterator.next();
            JUCtrlHierBinding treeBinding = null;
            CollectionModel collectionModel = (CollectionModel)tree.getValue();
            treeBinding = (JUCtrlHierBinding)collectionModel.getWrappedData();            
            JUCtrlHierNodeBinding nodeBinding = null;
            nodeBinding = treeBinding.findNodeByKeyPath(key);
            Row rw = nodeBinding.getRow();
           
            int seqId = ((BigDecimal)rw.getAttribute("ChecklistStructureId")).intValue(); // We can get the column name value from that node or row. 
            String elementId=((BigDecimal)rw.getAttribute("ElementId")).toString();
            String ChecklistStructureId=((BigDecimal)rw.getAttribute("ChecklistStructureId")).toString();
            String ElementName=(String)rw.getAttribute("ElementName"); 
           
           
            Object result = ob1.execute();
            //System.out.println("XXXXXXXXXXXX"+result.toString());
            if (!ob1.getErrors().isEmpty()){
                List errorList = ob1.getErrors();
                System.out.println("ERROR IN VC EXECUTION");
                // Capture and handle Error
            }   
        
     
    }
    }


        private Object invokeMethodExpression(String expr, Class returnType, Class[] argTypes, Object[] args){
           FacesContext fc = FacesContext.getCurrentInstance(); 
           ELContext elctx = fc.getELContext();
           ExpressionFactory elFactory = fc.getApplication().getExpressionFactory(); 
           MethodExpression methodExpr = elFactory.createMethodExpression(elctx,expr,returnType,argTypes);    
           return methodExpr.invoke(elctx,args); 
        }

Happy coding with Techartifact

getting current row of table in ADF

Requirment- Get the current row of table in ADF

         DCBindingContainer bindings = (DCBindingContainer)getBindings();                
        DCIteratorBinding dcIter = bindings.findIteratorBinding("IOOrderLinesVO4Iterator");
         RowSetIterator lineRSIter = dcIter.getRowSetIterator();
        Row r = lineRSIter.getCurrentRow();

Access one Managed Bean from another in JSF 2.0 | Techartifact

Requirement- Access one Managed Bean from another in JSF

Solution- There are two ways-

Dependency Injection

We can use JSF 2 @ManagedProperty annotation

In the managed bean add a @ManagedProperty annotation to the related property

@ManagedBean(name="currentBean")
@RequestScoped
public class CurrentBean 
{

    @ManagedProperty(value="#{requiredBean}")
    private RequiredBean requiredBean;

    public RequiredBean getRequiredBean()
    {
        return requiredBean;
    }

    public void setRequiredBean(RequiredBean requiredBean)
    {
        this.requiredBean= requiredBean;
    }

    // ....


}

Usingthrough faces-config.xml

<managed-bean>
   <managed-bean-name>requiredbBean</managed-bean-name>
   <managed-bean-class>vinay.common.RequiredBean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>

 <managed-bean>
   <managed-bean-name>currentBean</managed-bean-name>
   <managed-bean-class>vinay.common.CurrentBean</managed-bean-class>
   <managed-bean-scope>request</managed-bean-scope>
   <managed-property>
     <property-name>requiredbBean</property-name>
     <value>#{requiredbBean}</value>
   </managed-property>
 </managed-bean>

Following are the constraints:

-> The current bean must have scope which is the same as or shorter than the required bean
-> The using bean must have a property-setter method which takes the required bean as a parameter
-> The beans cannot have managed dependencies on each other.