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!

6 comments:

  1. can we get sample code here please

    ReplyDelete
  2. Replies
    1. I've updated the post with an alternate solution that may be useful to you.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. may be someone will need to copy the source, to save your time I posted it here

    <af:serverListener type="onPageLoad" method="#{activitiBean.onTableRowSelection}" />
    <af:clientListener method="triggerOnLoad" type="load"/>
    <af:resource type="javascript">
    function triggerOnLoad(event){
    AdfCustomEvent.queue(event.getSource(),"onPageLoad",{},false);
    }
    </af:resource>

    ReplyDelete
  5. Las Vegas Forum - Casino - JT Hub
    I do recommend the 시흥 출장마사지 casino at a smaller 전라북도 출장안마 casino. 과천 출장안마 It 남원 출장샵 is great for anyone that doesn't need an internet connection. 문경 출장마사지 Rating: 4 · ‎1 review

    ReplyDelete