Home » General

Oracle ADF Basics: Getting values of the multiselected rows in an af:table

Written By: Pascal Alma on April 19, 2008 4 Comments

In a former post I described how you could get access to the selected row in you af:table in your backing bean. This post takes it a step further and shows you how to deal with a multiselect table.
Let us first look at how to create a multi select table. Because this can't be done by drag-and-drop at once, you will first have to drop the view object on your page as a (read-only) table and then tick the checkbox for single selection in the af:table wizard, that is started and finish the wizard.
You can then go to source code of your page and edit the created tag manually from:
af:tableSelectOne
to:
af:tableSelectMany
After doing that you select the 'af:table' component in your 'structure pane' and clear the properties 'SelectionListener' and 'SelectionState (These properties refer to listeners that will only work on the last selected row and not all the selected rows). Now we are working in the property palette anyway we can also fill in the 'Bind' property so we bind the 'af:table' component to a backing bean, like this:
Backing Bean Creation Wizard
MultiSelect Table Bean
That's all it takes to create a multiselect table and make it available to your code!
To get access to the selected rows in the table, in this example, you will have to use in your backing bean:

JAVA:
  1. // Get the (Oracle.jbo)keys of the rows that are selected in the table
  2. this.getMyTable().getSelectionState().getKeySet();
  3.  
  4. // To clear the selected checkboxes:
  5. this.getMyTable().getSelectionState().clear();

or in a JSF EL expression:

XML:
  1. #{backing_multiselecttable.myTable.selectionState.keySet}

The latter is very handy if you create a method in your ApplicationModule, which has as a parameter a Set (containing Oracle Keys), like the following example, which will delete the rows that belong to the incoming set of primary keys:

JAVA:
  1. public void deleteRecords(Set primaryKeys)
  2.   {
  3.     for (Key primaryKey: (Set<Key>) primaryKeys)
  4.     {
  5.       Row rowToRemove = getForemanRequestDets().getRow(primaryKey);
  6.       if (rowToRemove != null) {
  7.         rowToRemove.remove();
  8.       }
  9.     }
  10.   }


After publishing this method in your Application Module by putting it in your 'Client Interface':
Add to Client Interface
you can drag and drop it on your page with the multi select table as a button and set the parameter value to the selected rows in the af:table, like this:
Binding delete method
I guess this shows it is rather easy to use the multiple select table. You only have to make sure the underlying view object of the 'af:table' component has at least one 'Key Attribute' defined. If not, the Set with keys will contain Integer values referring to the number the selected row has in the 'af:table' which isn't very usefull to select rows in a view object.

Tags:

Digg this!Add to del.icio.us!Stumble this!Add to Techorati!Share on Facebook!Seed Newsvine!Reddit!Add to Yahoo!

4 Responses to “Oracle ADF Basics: Getting values of the multiselected rows in an af:table”

  1. naveen said:

    Hi ,
    I have a question on this...
    how to access the selected row data in the backing bean..
    if the table has 3 columns how to access each column individually

  2. Pascal Alma said:

    @Naveen,

    The easy (but rather ugly) way would be to add these three columns to the Key of the row. That way you can access the selected values directly in the KeySet in your backing bean.
    An alernative would be to use the selected Key to get the complete row from the ViewObject and get the necessary values for each column, but that makes an extra roundtrip to the DB necessary.
    Hope this helps.

  3. naveen said:

    Hi Pascal,
    I am new to faces. could you please tell me how columns can be added to key..
    In my scenario i am using a webservice data control for the table. I didnt create a view object..

  4. Pascal Alma said:

    Hi Naveen,
    I haven't used this table component with a web service data control, so I don't know how that works. May be it is best to post your question at the OTN forum: http://forums.oracle.com/forums/forum.jspa?forumID=83
    Sorry I can't help you with this.

Copyright © 2009 Pascal’s Blog, All rights reserved.| Powered by WordPress