Click
Click Examples

Source Viewer : WEB-INF/classes/org/apache/click/examples/page/introduction/ControlListenerType2Page.java

package org.apache.click.examples.page.introduction;

import org.apache.click.ActionListener;
import org.apache.click.Control;
import org.apache.click.control.ActionLink;
import org.apache.click.examples.page.BorderPage;

/**
 * Provides a control listener example Page using the compile time binding of
 * the control ActionListener.
 * <p/>
 * The advantage of this control listener binding style is you get compile
 * time safety and compiler refactoring support, the disadvantage is that you
 * have to write more lines of code.
 */
public class ControlListenerType2Page extends BorderPage {

    private static final long serialVersionUID = 1L;

     private ActionLink myLink = new ActionLink("myLink");

    // Constructor ------------------------------------------------------------

    /**
     * Create a new Page instance.
     */
    public ControlListenerType2Page() {
        addControl(myLink);

        myLink.setActionListener(new ActionListener() {
            private static final long serialVersionUID = 1L;

            public boolean onAction(Control control) {
                 String msg = "ControlListenerPage#" + hashCode()
                 + " object method <tt>onAction()</tt> invoked.";
                 addModel("msg", msg);

             return true;
            }
        });
    }

}