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!

Tuesday, May 31, 2016

Long text in ADF output text component

When longer texts are displayed in a column of ADF table, it is not entirely visible. One has to stretch the column width or hover over the cell to view the entire text.



This can be avoided in two ways:

1. Convert the outputText component to inputText and make the read only property as true.
    Set the 'rows' property of inputText to more than 1 (depending on the text you have)
    If we have set the rows to 3 and text is much longer, scroll bar would appear.
                           
                         

2. By setting inline style for the outputText, we can achieve the desired.
  
     inlineStyle="white-space: pre-wrap; word-wrap:break-word; display:inline-block;"
     noWrap="true"
     styleClass="AFStretchWidth"

                      

    Either of the methods avoid text wrap issues in ADF tables.