Posted on Wednesday, 7 July 2010 by
Theo van Arem
In ADF you can present values as {‘Y’,'N’} or {‘YES’ ,’NO} with a dropdown box. But when you have to have a high usability of you application you would like to use checkboxes for boolean values instead of drop down boxes. In ADF this can be achieved by putting the values into a LOV and adjust the display type to checkbox. To show how it’s done i have made the following step by step example:
I have created in the hr schema of the database a person table with different boolean indicators.
CREATE TABLE "HR"."PERSONS"
( "ID" NUMBER NOT NULL ENABLE,
"BLN" NUMBER NOT NULL ENABLE,
"YNBLN" VARCHAR2(1 BYTE) NOT NULL ENABLE,
"YESNOBLN" VARCHAR2(20 BYTE),
"EMAIL" VARCHAR2(20 BYTE),
CONSTRAINT "PERSONS_PK" PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
In the three BLN columns i store in a different way a indicator value.
- Number: {1:true, 0:false}
- Char: {Y:true, N:false}
- String: {Yes:true;No:false}
After creating the table i made a ADF model application and created a Entity Object on this table and a view object based on the entity object.

When running the Application Module for a test you see the default presentation of the fields are input fields.

Changing the presentation of the number boolean indicator is quite straight forward. In the entity object Person we change the Attribute Type of Bln from Number (as it’s defined in the database) to Boolean. Because the entity knows that the Database Column is a numbered datatype it will take care of the data conversions. After this change we restart the Application Module. We see now that the numbered value presentation is been replaced by an check-box. This is done because the entity objects treats the values as a Boolean instead of a numbered value, and this conversion is quite easy to do.

Converting a boolean value to {Y,N} or to {YES, NO} needs some more work. You can use different solutions, you can generate a specific entity class where you do the conversion from boolean to any other data type. I have chose to use a static LOV list to convert boolean values to other data types values.

I created the LOV with three attribute values: Boolean, Char and String. This to show the working of different data types, it would be quite strange to have in a single application different way’s of storing boolean values.

I have given them the following values in a fixed list.

After specifying the LOV we have to tell the View Object that it should use the values from the LOV to be stored as a representation of the check or unchecked state of the checkbox. This is done in the following way.
Open of the View Object the tab View Accessors and press the green + to add a View Accessors. Shuffle the YesNoLOV to the right pane.

After adding the LOV as a View Accessor we go to the Attributes tab of the View Object and select the attribute that we want to change in this example Ynbln. We want to let the checkbox represent a Y value when checked and otherwise a N. To do this we select the Ynbln attribute and press the green + at the bottom of the screen to add a List of Values. Select in the Data Sourece List the added YesNoLOV1 that we created as a View Accessor and specify the column that the checkbox should represent. In this case the column valueYN.

Select no the tab UI Hints. Uncheck here at the option ‘Include “No Selection” Item:’ in the Choice List Options. We want always a value Y or N we don’t want a null value if the checkbox is not pressed.

Now we have configured the presentation of this attribute. Default the View Object will represent the value with a dropdown listbox. To use the checkbox we have to open the View Object and edit the specified attribute ‘Ynbln’. We select the Control Hits item on the left and alter the Control Type to ‘Check Box’.

Do you can do the same exercise for the attribute Yesnobln and use instead of the YNvalue the YesNo value.
To test the working of this solution run the Application Module and modify records. Check the modified records with SQL to check if the data that you have changed is stored in the correct format into the database.

As you see the corresponding results in the table.

Popularity: 87% [?]