Intercept Hide/Show column event

Lucas Jellema

 

When we wrap a rich table in a panelcollection component, we get some interesting additional functionality. This includes the ability for the end user to hide and display columns. It may be useful to intercept that column hide/show event – for example to influence the query that is executed to retrieve the data for the table.=

There is no column property hideAndShow Listener, nor is there a special listener on the panelCollection component. After a little trial and error, I found out that the column show/hide event can be intercepted using an attributeChangeListener on the column component:

        <af:panelCollection id="empTablePanelCollection"
                            attributeChangeListener="#{TableListener.attributeChangeListener}">
          <af:table value="#{bindings.emps.collectionModel}" var="row"   ...>
            <af:column sortProperty="job" sortable="true" id="colJob"
                       attributeChangeListener="#{TableListener.attributeChangeListener}"
                       ... >

The bean method is called with the attribute change event as parameter. From it, we can extract the component and attribute that were effected as well as the old and new value of the attribute.

package nl.amis.view;

import org.apache.myfaces.trinidad.event.AttributeChangeEvent;

public class TableListener {

    public void attributeChangeListener(AttributeChangeEvent attributeChangeEvent) {
        System.out.println(attributeChangeEvent.getAttribute());
        System.out.println(attributeChangeEvent.getComponent().getId());
        System.out.println(attributeChangeEvent.getNewValue() +" old value "+ attributeChangeEvent.getOldValue());
    }
}

The debugoutput in the console:

visible
colJob
true old value false

In later articles we will use this approach to set the values of bind parameters depending on columjns being hidden or shown.

Next Post

Bulk Operations in PL/SQL

When I was in Chicago for the OPP2008 and APEXposed event I talked to someone who seems to have trouble understanding bulk operations in PL/SQL. I helped him out by providing a test/demo script, that shows how it could be done. First of all, one of the most important rules […]