Showing posts with label RowSelection. Show all posts
Showing posts with label RowSelection. Show all posts

Wednesday, June 1, 2016

Selection listener for first row in a table

When certain actions are desired on a row selection in ADF table, the business logic is written in selection listener of the table.

But this method fires only on manual row selection and not for the default row selected on the page load.

Scenario: Let's say we have a master and child tables and I intend to set properties on child table rows based on row selected in master table.

Irrespective of whether RowSelection of master table is 'single' or 'none', child table is rendered with first row of master, via the view link.

Our selection listener isn't in action for this initial row. i.e., even if I have logic in selection listener of Master table, it does not execute.

Workaround in ADF 11.1.1.7
To overcome this, we may have a piece of code in bean and point it to render property of UI component enclosing the table.
We make sure that this executes only one based on a scope variable 'checkCount'.

public boolean isRendered(){
       if(checkCount==0){
            doEnableDisable();
            checkCount +=1;
        }
        return true;
}

If table is surrounded by a panelGroupLayout, rendered property of panelGroupLayout would be #{bean.renderedPB}

Note:
11.1.1.7 does not support methods to be in executable region. (it is deprecated)

Another alternative is to use clientListener and serverListener in tandem.

Let us consider an example with a table showing numbers and on row selection, selected number is displayed in an output text. Though rowSelection is set to single, no number is shown in output text on page load.





Now, let's implement the listener approach.


 Method 'selectOne' has same logic as the selection listener. This is triggered on page load using javascript. Both the listeners have to be placed under 'document' tag.


There we go!