Monday, 28 December 2015

ADF | Fetching Multiple selected Rows from a Table populated from POJO in ADF

Hi,

This is again an Extension to my previous post on how we can perform edit on a table populated from POJO. http://adfjavacodes.blogspot.com/2015/12/adf-performing-edit-in-table-from-pojo.html

Everything is same from my previous post.
There are certain changes in the application. They are :

Here I have enabled Multiple row selection for the table from the property inspectior to
 <af:table var="row" rowBandingInterval="0" id="t1" value="#{viewScope.BookBean.bookInfo}"
                                  rowSelection="multiple" binding="#{viewScope.BookBean.tableBinding}">

I have also created a binding of the table for getting the  Multiple selected rows from the table.
Here is the code of the of the Bean where I have created a method that will fetch the selected rows from the table.


package edittableonpojo.view.bean;

import edittableonpojo.view.dc.BookInfo;

import java.util.ArrayList;

import java.util.Iterator;

import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.view.rich.component.rich.data.RichTable;

import org.apache.myfaces.trinidad.model.RowKeySet;

public class BookBean {
    private ArrayList<BookInfo> bookDtls = new ArrayList<BookInfo>();
    private RichTable tableBinding;

    public BookBean() {
        bookDtls.add(new BookInfo("1A", "The Alchemist", "Paulo Cohelo"));
        bookDtls.add(new BookInfo("2A", "Game Of Thrones", "George R. R. Martin"));
        bookDtls.add(new BookInfo("3A", "Five Point Someone", "Chetan Bhagat"));
        bookDtls.add(new BookInfo("4A", "Harry Potter", "J.K.Rowling"));
        bookDtls.add(new BookInfo("5A", "Wings of Fire", "A.P.J Abdul Kalam"));
    }

    public ArrayList<BookInfo> getBookInfo() {
        return bookDtls;
    }
    
    public void printValues(ActionEvent ace){
        for(BookInfo row : bookDtls){
            System.out.println("Row : "+row.toString());
        }
    }

    public void fetchSelectedValuesAL(ActionEvent actionEvent) {
        ArrayList<BookInfo> selectedRows = new ArrayList<BookInfo>();
        RowKeySet keySet = getTableBinding().getSelectedRowKeys();
        Iterator<Object> itr = keySet.iterator();
        while(itr.hasNext()){
            // next gives the index of the selected row
            Object next = itr.next();
            // here we have fetched the row on index from the bookDtls list
            selectedRows.add(bookDtls.get((Integer)next));
        }
        System.out.println("Selected Rows are : "+selectedRows.toString());
    }

    public void setTableBinding(RichTable tableBinding) {
        this.tableBinding = tableBinding;
    }

    public RichTable getTableBinding() {
        return tableBinding;
    }
}

On running the application ,  I have selected Two rows from the table.

On clicking "Get Selected Values" button.



Here is the Sample Application : EditableTableOnPOJO.rar

Performing Edit in a table from POJO in Oracle ADF

Hi,

This post is about Editing the values of the Table. You can learn how to populate table from the arrayList from my previous blog.http://adfjavacodes.blogspot.com/2013/04/adf-populating-adf-table-from-bean.html


Every step is same as in my previous post.
There only one thing needs to be changed. Suppose here we have to edit the BookDesc from the front End.
For doing this, We just need to provide the editable property in an inputText and that’s it. The editing in automatically handled.

We have to edit the Book Description Column, So I have just replaced the output text component with an input text. Here is the code for the same.

Here is the code of the jspx page. I have also added a button to print the updated Values of the List.

On running the page .

Now I have changed the Description of one Book to 
On clicking Show Current Values in the List  values are being printed in the console like


SO as we can see the row have been updated.

Here is the Sample Application : EditableTableOnPOJO.rar