Intercept Hide/Show column event

0
Share this on .. Tweet about this on Twitter0Share on LinkedIn0Share on Facebook0Share on Google+0Email this to someoneShare on TumblrBuffer this page

 

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"
                       <strong>attributeChangeListener=&quot;#{TableListener.attributeChangeListener}&quot;</strong>
                       ... &gt;

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() +&quot; old value &quot;+ 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.

Share this on .. Tweet about this on Twitter0Share on LinkedIn0Share on Facebook0Share on Google+0Email this to someoneShare on TumblrBuffer this page

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PL/SQL), Service Oriented Architecture, BPM, ADF, JavaScript, Java in various shapes and forms and many other things. Author of the Oracle Press books: Oracle SOA Suite 11g Handbook and Oracle SOA Suite 12c Handbook. Frequent presenter on conferences such as JavaOne and Oracle OpenWorld. Presenter for Oracle University Celebrity specials.

Comments are closed.