Click
Click Examples

Source Viewer : WEB-INF/classes/org/apache/click/examples/page/ajax/PageActionPage.java

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

import org.apache.click.ActionResult;
import org.apache.click.control.ActionLink;
import org.apache.click.examples.page.BorderPage;

/**
 * Demonstrates how a Page Action can be used to handle an AJAX request.
 * The Page Action is invoked by Click to handle the AJAX request.
 * The Page Action method returns an ActionResult that is rendered to the
 * browser.
 *
 * A Page Action is a regular method defined on a Page with the following signature:
 * - the method must take no arguments
 * - the method must return an ActionResult
 *
 * PageActions provide the simplest way to handle Ajax requests.
 *
 * The client-side is implemented using the jQuery library.
 */
public class PageActionPage extends BorderPage {

    private static final long serialVersionUID = 1L;

    public PageActionPage() {
        ActionLink link = new ActionLink("link", "here");
        link.setId("link-id");
        addControl(link);
    }

    // Note the pageAction method signature: a no-arg method returning an ActionResult
    public ActionResult onLinkClicked() {
        // Formatted date instance that will be returned to the browser
        String now = format.currentDate("MMM, yyyy dd HH:MM:ss");

        String msg = "PageAction method <tt>onLinkClicked()</tt> invoked at: " + now;

        // Return an action result containing the message
        return new ActionResult(msg, ActionResult.HTML);
    }
}