Wednesday, March 21, 2018

ADF - Get Selected Rows - Single/Multi Selection


//Single Selection

    public String singleSelection_action() {
        // Add event code here...
       
        System.out.println("User Clicked on Single Button");
       
        DCBindingContainer bindings =
                    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
                DCIteratorBinding dcItteratorBindings =
                    bindings.findIteratorBinding("EmployeeEOVO1Iterator");
               
        // Get an object representing the table and what may be selected within it
                ViewObject voTableData = dcItteratorBindings.getViewObject();
       
                // Get selected row
                Row rowSelected = voTableData.getCurrentRow();
       
                // Display attribute of row in console output - would generally be bound to a UI component like a Label and or used to call another proces
                System.out.println(rowSelected.getAttribute("EmployeeId"));
               
               
               
        return null;
    }


//Multi Selection

    public String multipleSelection_action() {
        // Add event code here...
        System.out.println("User Clicked on Multiple Selection ");


        // RowKeySet Object can hold the selected rows from a user as follows
                RowKeySet rksSelectedRows =
                    this.getT1().getSelectedRowKeys();

                // Iterator object provides the ability to use hasNext(), next() and remove() against the selected rows
                Iterator itrSelectedRows = rksSelectedRows.iterator();

                // Get the data control that is bound to the table - e.g. OpenSupportItemsIterator
                DCBindingContainer bindings =
                    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
                DCIteratorBinding dcIteratorBindings =
                    bindings.findIteratorBinding("EmployeeEOVO1Iterator");

                // Information from binding that is specific to the rows
                RowSetIterator rsiSelectedRows =
                    dcIteratorBindings.getRowSetIterator();

                // Loop through selected rows
                while (itrSelectedRows.hasNext()) {

                    // Get key for selected row
                    Key key = (Key)((List)itrSelectedRows.next()).get(0);

                    // Use the key to get the data from the above binding that is related to the row
                    Row myRow = rsiSelectedRows.getRow(key);

                    // Display attribute of row in console output - would generally be bound to a UI component like a Label and or used to call another proces
                    System.out.println(myRow.getAttribute("EmployeeId"));
                }
               
               
               
               
        return null;
    }

No comments: