Wednesday, February 5, 2014

Working with the selectManyCheckbox component

I recently came across a simple, yet not so straightforward use case as it seems for many ADF developers on the JDeveloper & ADF forum so I decided to blog about it.

The requirement was to use the selectManyCheckbox component and to save the selection in the database in a varchar2 column of type.

So I created a custom table in the HR schema, MY_EMPLOYEES with 3 columns; ID (number), NAME (varchar2) and  DEPARTMENTS (varchar2).


I then created the basic ADFBC objects (an entity MyEmployees based on the MY_EMPLOYEES table, a view MyEmployeesView based on the MyEmployees entity and an application module AppModule that has the MyEmployeesView selected in the data model).


Moving on the ViewController project, i created a page (employees) where i dragged the MyEmployeesView view object as an ADF Form (JDeveloper created automatically for me the 3 attributes Id, Name and Departments).

From the component pallet i added  a selectManyCheckbox component, accepting the default settings (just changed the label to Departments) and a button component (which i called Save).


In the page bindings I just added the Commit operation as an action (so that i can invoke it from the Save button).

All the logic is implemented in a managed bean with scope set to pageFlowScope. Both the selectManyCheckbox and selectItems values are set from the bean. 



Same goes with committing the data (selected departments). This is handled via a bean method.

  
You can test the application by running the employees.jspx page. Select one or more departments and click save. The selection array is stored in the varchar database column.


On loading the page the bean will convert the string back into an array and assign it to the selectManyCheckbox component.

Download Sample Application - WorkingWithTheSelectManyCheckboxComponent

No comments:

Post a Comment