Intercept Hide/Show column event


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.=

Intercept Hide/Show column event adfbcdeclarative58

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"
          <af:table value="#{bindings.emps.collectionModel}" var="row"   ...>
            <af:column sortProperty="job" sortable="true" id="colJob"
                       ... >

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.getNewValue() +" old value "+ attributeChangeEvent.getOldValue());

The debugoutput in the console:

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.