Sunday, May 16, 2010

Adding Boolean Checkbox to Table Component in Oracle ADF

Hi,

I have seen many people asked this question at OTN forums so i decided to blog it.

In Oracle ADF  af:selectBooleanCheckbox and af:selectBooleanRadio component has Boolean datatype which is not actually SQL supported data type (In Oracle we have Boolean in PL/SQL) and most of us stores boolean column values as Y/N or 1/0 in our tables.

Solution is pretty simple you have to add transient attribute in your ViewObject and set the values to your actual attribute based the values in transient attribute

Follow these steps:

1) Add a Transient Boolean attribute in your VO
2) Generate a Java class ViewRowImpl with Accessors of your VO
3) Set your attribute's values in Transient getter and setter method

Heres the example:
Create a table called checkboxer

create table checkboxer
(date_val timestamp,
 check_status varchar2(1 char));

- Create a ADF application and add checkboxer's EOs VO and AM

- Add a Transient attribute called StatusBoolean in VO

- Generate ViewRowImpl class replace the existing code with as shown in the slide


- Thats all Run the Business component browser and check the values
- Drop a collection as ADF table and right click the StatusBoolean column and choose Convert to.. and select Checkbox boolean.

Download the workspace

Happy Jdeveloping,
Baig

15 comments:

  1. Baig,

    I like all your posts.
    You covered all complex and good scenarios so well.
    Your blog has always helped me so much.

    ReplyDelete
  2. Thanks prabhanjan,

    I am glad you find my blog useful.

    ReplyDelete
  3. Hi Baig,
    I had to create a flag of VARCHAR2(1) AND SHOW IT ON THE PAGE AS CHECKBOX.i FOLLOWED THE SAME PROCEDURE AS MENTIONED IN THE BLOG.iTS STROING THE VALUE FOR A SESSION OF THE PAGE,BUT NOT ABLE TO STORE IN DATABASE PERMANENTLY.

    ReplyDelete
  4. Thank you,Baig. Your blog is very useful.

    ReplyDelete
  5. Hi,
    Thanks for a wonderful post.

    I am using your code in a popup which has a table with checkboxes.

    In the above setStatusBoolean() how do I set the value of a VO attribute to the value from #{viewScope.Status}.

    Can you give me the syntax please?

    ReplyDelete
  6. Hi rocky,

    if you have that VO attribute available on your ADF page binding then use af:setPropertyListener to assign value on your event.

    Other you can write a logic in a managed bean. the syntax to read values from viewScope can be found in ADFUtils and JSFUtils classes.

    ZB

    ReplyDelete
  7. Hi Baig,

    I want to add a column to a table which allows me to navigate to a new page.
    How can we achieve it, can you please share it.

    ReplyDelete
  8. Hi Baig,

    I've struggled with this as well, but I've found an easier solution to this problem using a NUMBER database column. This solution requires no code at all.

    You can check my post at https://forums.oracle.com/forums/message.jspa?messageID=10138292#10138292

    ReplyDelete
  9. hi...
    i created on table in that one column is boolean checkbox..so i want that if i select the boolean checkbox in column name itself it should select all the row..if i deselect it it should reflect to all the rows hot to do it...

    ReplyDelete
  10. Hi, Baig
    I am new on ADF, I have one query in my application i am using one attribute OperatingDays. now i want use SelectManyCheckBox for this attribute, like this
    Monday 1
    Tuesday 2
    Wednesday 3
    ......
    ......
    Sunday 7

    (1,2,3,4,5,6,7 these are the value of days) now my query is when i select monday operatingdays attribute value will be 1 if i selected monday and tuesday then value will be 1,2 and so on.

    please help me to sort out this issue.
    Thanks
    Nishant

    ReplyDelete
    Replies
    1. Hi,

      Check this post it is about shuttle but concept is same. http://www.baigzeeshan.com/2010/10/creating-shuttle-component-in-oracle.html

      ZB

      Delete
  11. I have a jsff page which shows rows in a table. The rows also have a check box next to each row. At the bottom of the table is a submit button. On clicking submit how do I know which rows had their check boxes selected

    ReplyDelete
    Replies
    1. Hi,

      Check this post where i am deleted all selected rows. you can just check the value of attribute binding.

      http://www.baigzeeshan.com/2010/06/deleting-multi-selected-rows-from-adf.html

      Zeeshan

      Delete
  12. Hi Baig,

    i am trying to implement a similar scenario by following your blog.

    my requirement is:
    ---------------
    1. when i check the checkbox in UI, it should pass 1 to the database query----> This is working fine.

    2. when i leave the checkbox empty in UI, this condition should not be included in the Where condition at all, and it should list all the rows(rows with "Y" and also, rows with "N").But, when i leave the checkbox empty, even then , query is filtered upon "IsYesNO" column.

    How can i stop this ?

    -Venkat

    ReplyDelete
  13. HI Baig,

    I have the similar requirement where a Checkbox is displayed for each row.
    User can select multiple rows, after selection of multiple checkbox user click a button. During this action, the number of rows user has selected should be counted.

    As of now, I am getting NULL when I try to check Row.getAttribute(checkBox) for all the rows but I am expected to get the value as "true" for selected rows.

    Please check and let me know some input to proceed.

    regards.

    ReplyDelete