Friday, July 17, 2009

In this post I will describe how to use multi-selection feature in ADF Faces. First of all I should say - multi-selection feature is fully supported by ADF Faces af:table component. However, those who are trying to use this feature for the first time, may have different opinion. You may ask - why? Simply, because multi-selection table by default may have one unneeded property, and this property is a source of a problem for those who are trying to use multi-selection. Which property is unneeded? Ok, let's look deeper and imagine that it is our first time when we are enabling multi-selection table and we have not used it before. One of the possible ways to create multi-selection table is:
  1. Drag and drop method return from Data Control Pallete in JDeveloper, and from pop-up window choose to create ADF Read-only Table. In my sample I'm using method return for Departments;

  2. In Edit Table Columns dialog select 'Enable selection' check-box. Press OK;
  3. Single-selection table in JSPX page is created;
  4. Using right mouse button, click on af:table element in Structure window and choose Properties;
  5. In Table Properties dialog select Formatting tab and instead 'Single Selection' choose 'Multiple Selection' for 'Include Selection Column' option. Press OK.
For af:table component, in JSPX should be generated by JDeveloper something like this:


Ok, there is enough only five steps, to create multi-selection table, let's test it. When table is opened, first row is selected by default. Hm..., it is like in single-selection table.


If you do not care about first row selected by default, let's randomly select any three rows and press Select button:


After Select button is pressed, only row for 'Human Resources' becomes selected:


So, it seems something is not ok. I have decided to research more deeper and have created 'Action Method Binding' for Select button in Backing bean. This method retrieves keys for the selected rows and prints information contained in those rows.


When selectButton_action() method was implemented, I have tested created multi-selection table for the second time. I have selected three rows and pressed Select button, in JDeveloper Log window was displayed only one row (should be three):

07/02/17 12:01:32 Selected Department: Human Resources

So, finally we have found a problem - multi-selection is enabled, but it works like a single-selection. How to solve this? Thanks God, it is simple - there is one property we should remove for af:table component:

selectionState=
"#{bindings.findAllDepartments1.collectionModel.selectedRow}"

Yes, selectionState set to 'selectedRow' is not needed in multi-selection table - remove it. When this property is removed, multi-selection feature works fine. Output in JDeveloper Log window, when three rows are selected:

07/02/17 12:09:39 Selected Department: Human Resources
07/02/17 12:09:39 Selected Department: IT
07/02/17 12:09:39 Selected Department: Executive

Download developed sample - MultiSelection.zip. Model layer for this sample is developed using Oracle TopLink, standard HR schema DEPARTMENTS table is used. View layer is implemented using Oracle ADF Faces. Sample contains one JSPX page - multiSelection.jspx, where described multi-selection table functionality is implemented.
Friday, July 3, 2009

Reusability in Oracle ADF Business Components

In Oracle ADF it is possible to create libraries for common solutions, and to reuse them later in several projects. This gives more productivity, project developer doesn't need to start from nothing - he will have working solutions at hand. If you would like to do this, there are instructions available in Oracle ADF Developer's Guide For Forms/4GL Developers - 25.7 Working with Libraries of Reusable Business Components.

There is nothing special when creating reusable library. In fact, you will need just to create specific deployment profile - Business Components Archive. This profile is used to create two JAR files - *CSMT.jar and *CSCommon.jar, which should be included into other projects. When reusing created library, developer will need to import those JAR files - instructions are available in Oracle ADF Developer's Guide (see above). After that, when library will be successfully imported, it will be possible to use provided components in Oracle ADF Business Components wizards.

Developed sample application is divided into two parts - CountriesReusableLibrary.zip and RegionsCountries.zip. In first part reusable library is implemented, it comes under lt.andrejusb.model.reusable package - Entity and View object for COUNTRIES table from standard HR schema are created. Implemented reusable library contains deployment profile. Second part implements support for REGIONS table and reuse developed library.

Sample application page flow logic:


Locally implemented Regions functionality:


Show countries button invokes imported functionality. Countries for selected region are displayed in the table:


Functionality in View layer is implemented in common way, it doesn't depend on reusability we have used. For 'Show countries' af:commandButton is created af:setActionListener, that stores selected #{row.RegionId} value into #{processScope.regionId}. Data for table contained in countries.jspx page comes from imported component, this table depends on selected #{row.RegionId}. Dependency is implemented using ExecuteWithParams action and setRegionId invoke action.

ExecuteWithParams definition in countries.jspx page definition file:


setRegionId invoke action definition:


So, reusability in Oracle ADF Business Components can be achieved really easy - this may help to develop your projects more effectively.

When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.