Translate

Saturday, December 14, 2013

Solution to "Select All checkbox in column header not working."

It is a very common requirement or usecase to have a Boolean Checkbox in the column header of an af:table and checking that would select all rows and unchecking that would deselect all rows. (all the rows in the table will be having a checkbox column)

So, recently I was also having the same requirement and tried to implement it as it is a pretty straight forward task. (have the autosubmit of the column header checkbox to true and on value change, iterate through the records, set the boolean variable to true and refresh the table.)

Then I run the page and see the funny thing, the value change doesn't work for the first time. From second time onwards it starts working.

Solution:

After the end of iteration and partial trigger, try to reset the table's state like below.

     yourtTableBinding.resetStampState();

What this does is, it refreshes the data with the updated model and clears the submitted value.

Hope this helps. :)





5 comments:

  1. Hi,

    I have exactly the same issue as mentioned in this blog. However the solution posted here did not resolve the issue for me. Can you please paste the code snippet here.

    Thanks

    ReplyDelete
  2. I am also looking for the logic to have a select/unselect all implementation. Can you provide the code snippet of the jspx and the backend bean logic.

    Thanks.

    ReplyDelete
  3. Hi,

    Here is the snippet. This method will be called from bean for select all, deselect all. True is passed for select all, false for deselect all.


    public void selectDeselectAll(Boolean flag){
    ViewObjectImpl deptVO = getDepartmentsVO1();
    RowSetIterator rs = deptVO.createRowSetIterator(null);
    if(rs != null){
    rs.reset();
    while(rs.hasNext()){
    Row row = rs.next();
    row.setAttribute("Select", flag);
    }
    rs.closeRowSetIterator();
    }
    }

    Thanks
    Nitish

    ReplyDelete
  4. Hi I have implemented the selectAll/SlectNone as a checkbox .. On selecting/unselecting it calls the below method.. I dont see the rows below getting selected on clicking the checkbox.

    my jspx code is








    my bean method is :
    public void selectUnselectAll(ValueChangeEvent valueChangeEvent)
    {

    RichTable notifyEventsTable = getBlackoutNotifyEventsTable();
    int rowCount = notifyEventsTable.getRowCount();
    for (int i = 0; i < rowCount; i++)
    {
    notifyEventsTable.setRowIndex(i);

    if (((Boolean) valueChangeEvent.getNewValue()).booleanValue())
    {
    selectedRowKeySet.add(blackoutNotifyEventsTable.getRowKey());
    }
    else
    {
    selectedRowKeySet.remove(blackoutNotifyEventsTable.getRowKey());
    }
    }
    notifyEventsTable.setSelectedRowKeys(selectedRowKeySet);
    }

    ReplyDelete
  5. < af:column id="rh1" rowHeader="true" >
    < f:facet name="header" >
    < af:selectBooleanCheckbox id="selectAllCheckbox"
    autoSubmit="true"
    valueChangeListener="#{opcNotifyBlackoutsView.selectUnselectAll}"/ >
    < /f:facet>
    < af:selectBooleanCheckbox id="rowSelectCheckbox" value="#{opcNotifyBlackoutsView.blackoutNotifyEventsTable.selectedRowKeys.contained}"
    autoSubmit="true"
    valueChangeListener="#{opcNotifyBlackoutsView.updateEventSelect}"/ >

    < /af:column >

    ReplyDelete