Intercept Hide/Show column event

Lucas Jellema
0 0
Read Time:1 Minute, 17 Second

 

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.

About Post Author

Lucas Jellema

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
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 […]
%d bloggers like this: