Click
Click Examples

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

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

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

/**
 * An Ajax example using jQuery library.
 */
public class JqueryAjaxDemoPage extends BorderPage {

    private static final long serialVersionUID = 1L;

    private ActionLink link = new ActionLink("link", "Make Ajax Request");

    public JqueryAjaxDemoPage() {
        link.setId("link-id");

        addControl(link);

        // Add an Ajax behavior to the link. The behavior will be invoked when the
        // link is clicked. See the basic-ajax-demo.htm template for the client-side
        // Ajax code
        link.addBehavior(new DefaultAjaxBehavior() {

            @Override
            public ActionResult onAction(Control source) {
                // Formatted date instance that will be added to the
                String now = format.currentDate("MMM, yyyy dd HH:MM:ss");

                String msg = "Hello from jQuery at: " + now;
                // Return an action result containing the message
                return new ActionResult(msg, ActionResult.HTML);
            }
        });
    }
}