Source Viewer : WEB-INF/classes/org/apache/click/examples/page/ajax/compare/JavascriptAjaxDemoPage.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 JavaScript instead of a library such as jQuery, Prototype etc.
*/
public class JavascriptAjaxDemoPage extends BorderPage {
private static final long serialVersionUID = 1L;
private ActionLink link = new ActionLink("link", "Make Ajax Request");
public JavascriptAjaxDemoPage() {
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 JavaScript at: " + now;
// Return an action result containing the message
return new ActionResult(msg, ActionResult.HTML);
}
});
}
}