Pages

Sunday, June 24, 2012

Select/Deselect All check box in a table

Select All/Deselect All check box in a table is a common requirement. This can be implemented in multiple ways. In this blog, I will explain the steps, I used for one of my project.

Follow these steps:

-  Add a transient attribute(say SelectDept) of type Boolean in the view object. Don't forget to set the updatable property to Always. 

Drag and drop the view object from the data control as an ADF Table

- Convert the SelectDept column to SelectBooleanCheckBox. Add command links to select/deselect check box in the header facet of this column.

- Call managed bean methods on click of the command link. After all these modifications the column code should look like:


- The bean methods onSelectAll, onDeselectAll in turn calls the method selectAllDept, deSelectAllDept respectively in AMImpl.java. It basically iterate through the RowSetIterator of DepartmentsView and set the value of SelectDept attribute, depending on the method being called.


UI Page:

Instead of command links (Select All/Deselect All), you can have a select boolean check box as well. On selecting it, all the check box are checked and un-selecting it will un-check all the check box in the table.

This code is also available in sample work space. Uncomment the select boolean check box in the column header facet and put the partial triggers of this boolean check box on the table.


Sample Workspace:
Download the sample workspace from HERE.

21 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi Umesh,

    This works when I use the Select/Deselect All command links but nothing happens when I use a checkbox and call the AMImpl code from the value change listener of the checkbox. Is there anything different that needs to be done? I couldn't even download the sample workspace.
    Please help.

    ReplyDelete
  3. Hi Sohit,

    Sorry for the late reply.
    Actually my repository got corrupted. I uploaded the work space to a different location. Can you please try accessing it now?

    Even the check box issue is resolved in the updated work space.

    Thanks,
    Umesh

    ReplyDelete
  4. Hello Umesh - I am trying to implement SelectAll checkbox with pagination table. Would really appreciate if you could share your project

    ReplyDelete
  5. Excellent Umesh. I saw your comment in the code saying "If SelectBooleanCheckBox approach is used, don't forget to set the partial triggers of it on the table". I was missing this piece before. Thanks a lot!

    ReplyDelete
    Replies
    1. Hi, I am trying to implement using SelectBooleanCheckBox approach. I cannot assign the id of SelectBooleanCheckBox to table. It doesnt recognize. How did you resolve this issue?

      Delete
  6. Hi Umesh, I have applied ur approach but for the 1st time when I select SelectALL checkbox then nothing is happening but the moment I deselect and then select the SelectAll checkbox then all rows are getting selected.

    ReplyDelete
    Replies
    1. Hi Pruthiviraj,

      Have you tried both the approaches that i mentioned. If yes, can you please try it in a sample HR schema. If you are still unable to resolve it, please send me your workspace. I will have a look.

      Thanks,
      Umesh

      Delete
  7. I have refreshed the table also programmatically, AdfFacesContext.getCurrentInstance().addPartialTarget(clearanceWorksheet.getTable1());

    ReplyDelete
  8. Actually I have tried with SelectAll and DeselectAll links. Here the rows are getting selected first time, but those rows which are visible. The moment if we scroll down the table then those rows are not selected. Vice-versa is the case with SelectAll/UnselectAll Boolean checkbox, here the rows which are visible are not select but if we will scroll down the table then the next rows are selected.

    ReplyDelete
  9. I have given the RangeSize=-1 for the iterator from page's pageDef.

    ReplyDelete
  10. Can you check the rangesize of the rowsetiterator in the above code. It should be -1.

    ReplyDelete
  11. Hi,

    Even we have select all feature in one of our pages. The issue i have is if i do a select all then the check boxes are selected and once i move to other region and come back to this region then the link is still "Deselect All" but the check boxes are not selected. This is because the variable carrying this check box is a transient attribute.

    Is there any way to solve this issue:
    either we have to change deselect all to select all
    or make the check boxes checked as before navigation.

    ReplyDelete
    Replies
    1. Hi,
      Can you please check how the select All and Deselect All text is changing. If you are using any scope variable, try resetting this variable as soon as you are either navigating from this region or coming to this region again.

      Delete
  12. I Have One Requirement,I Have One Table with Single Check box,for data population using SOA.If i run the page default it shows only Active records(Status),If i click on check box,it will shows InActive records,followed by Active records,how to achieve,pls help me on this issue,here we are not using Direct DB.We have created Transient Attributes..

    ReplyDelete
    Replies
    1. Hi Viswa,
      You can populate a transient vo using the data retrieved from SOA. And then follow the steps mentioned in this blog.

      Delete
  13. Hello Umesh,
    When I click on the link the page show "File not found",
    Please update your link.
    Thank You

    ReplyDelete
  14. Hi Anas,
    Accidentally my workspace got deleted. I will try to create one in some time. But in case you have any doubts please let me know.

    Thanks,
    UMesh

    ReplyDelete
  15. Hi Umesh, I am trying to implement using SelectBooleanCheckBox approach. But I cannot assign the id of SelectBooleanCheckBox to partial trigger of table. It doesn't recognize. How can you resolve this issue? As soon as screen renders, I am getting "Caused By: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'row' resolved to null". I Appreciate it, if you could help me resolving this issue.

    ReplyDelete
    Replies
    1. Hi Sudha,
      You can take the workspace which i have attached. else send me your workspace. I will work on it.

      Thanks,
      Umesh

      Delete
  16. Hi Umesh,

    I am facing the same issue. I used a checkbox in the table column header to select / deselect all rows. When i run the application for the first time its working but after save or after clicking somewhere in the page its not working again. Can you please share me your idea?

    ReplyDelete