Clearing ADF Faces Table row section when change persistence is ON

Clearing af:table row section when change persistence is ON involves two steps:

1. Clearing the selected rows using table API
2. Call the change manager API to replace the current change persistence with an empty set

 Here is the code snippet for the above tasks:

public void clearRowSelection(RichTable table) {
    //Clearing the selected rows using table API 
    table.getSelectedRowKeys().clear();

    //Call change manager API to replace the
    //current change persistence with an empty set 
    RowKeySetAttributeChange rks =    new RowKeySetAttributeChange
        (table.getClientId(), 
            "selectedRowKeys", new RowKeySetImpl());
    RequestContext.getCurrentInstance().getChangeManager().
        addComponentChange(FacesContext.getCurrentInstance(),table, rks);
}

Comments

Billy Bob Bain said…
This was very helpful!
Keith Reardon said…
2 questions for you, 1) does this same code apply for af:treeTable, I hope so as we have this problem with af:treeTable, and 2) is there something similar to clear the disclosed row keys in af:treeTable as they also appear to be persisted and that interferes with logic to programmatically set disclosed rows.
Ankur Pradhan said…
Hi,

I am working af:tree, I need to achieve same functionality for RichTree.

When I tried same approach, I am getting below exception

Caused by: java.lang.IllegalArgumentException: No clientId specified

Code Tried:

RichTree orderTree = this.getOrderTree();
orderTree.getSelectedRowKeys().clear();
RowKeySetAttributeChange rks = new RowKeySetAttributeChange(orderTree.getClientRowKey(),
"selectedRowKeys", new RowKeySetImpl());
RequestContext.getCurrentInstance().getChangeManager().
addComponentChange(FacesContext.getCurrentInstance(),orderTree, rks);
}

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.