One of the favorite GUI items is the Checkbox. I use this GUI item often to enforce a ‘Yes’ or ‘No’ option.
If the item ‘Maintainable’ is checked, the database value has to become ‘Y’ and if unchecked, the database value has to become ‘N’. The underlying column definition is a mandatory varchar2(1) column which only may contain the values ‘Y’ or ‘N’.
First, create the check constraint (optional).
CONSTRAINT "OMP_DOMAINS_CHK1" CHECK (MAINTAINABLE IN ('Y', 'N')) ENABLE
Then we create the page-item ‘Maintainable’, set ‘Display As’ to Checkbox.

Because the item type of this item is ‘Checkbox’ we have to define a corresponding LOV. Create a STATIC LOV with only 1 value. Enter to ‘Display value’: and ‘Value: ‘Y’ This results in 1 checkbox without a suffix. Now we have only 1 checkbox, with can get two values, the ‘Y’ and the NULL.
If you submit the item unchecked, the NULL value is written to the database. This is not allowed because the underlying column is required. To avoid this error you have to create a before row trigger on the database table. This trigger translates the NULL value to ‘N’ and ensures that we don’t need any additional javasript.
create or replace trigger omp_dos_bru before update on omp_domains for each row begin :new.maintainable := nvl(:new.maintainable,'N'); end;
This is the server-side solution. If you are not able to implement a database trigger eg autorisation reasons, there is also a client side solution in APEX. Thanks Simon Boorsma for this sensible supplement. The only thing you have to do is to define a computation on submit after validations.





Whitehorses is specialized in succesfully implementing Oracle SOA solutions: BPEL, OSB, WebLogic & BPM
{ 3 comments… read them below or add one }
Why not use a computation ( on submit after validations) on the APEX screen, instead of the suggested database-trigger?
Thanks, you are right, thats also a nice solution. I’m still learnig every day.
HI JAN,
Can’t we define “DEFAULT” value for the column which as “N”. In this way when we the checkbox is unchecked, field will be “N” and when checked it will hold “Y”.
Regards,
Shijesh