AjaxController

AjaxController receives requests sent by the browser and routes them to AjaxAction classes through the application action mapper. It is the entry point for Ajax interactions.

Overview

A typical controller is a servlet extending AjaxController; the actions register with its action mapper in init(). Controller hooks can initialize or inspect each request.

Follow a real button request from the browser through the Ajax controller into a server action, then back as a PushAction.

CODE
Button button = new Button("Send Ajax request");
button.onClick(new AjaxActionUpdate());
layout.add(result).setId(AjaxActionUpdate.RESULT_ID);
RESULT
Click to update

Dialog example

A second request triggers a server-generated dialog while staying on the same page.

CODE
Button button = new Button("Open server dialog");
button.onClick(new AjaxActionOpenDialog()
        .addParameter("message","Hello from the server"));
RESULT

How it works

CODE
public class AjaxActionUpdate extends AjaxAction{
    @Override
    public void init(){
        setActionMapper(AjaxControl.instance.getActionMapper());
    }

    @Override
    public void perform(AjaxContext context) throws Exception{
        context.sendClientAction(
            new PushAction.UpdateElement(RESULT_ID,new Text("Updated"))
        );
    }
}

Reading parameters

Parameters supplied on an action are available on the request.

CODE
String message = context.getRequest().getParameter("message");
context.sendClientAction(new PushAction.OpenModalDialog(dialog));

Design guidance

Usually you define one Ajax controller for an application area and multiple small AjaxAction classes. Controller hooks are appropriate for request-wide checks, not component-specific UI.

Full API reference

These examples introduce the most important behavior without attempting to document every method. For the complete reference, see https://doc.jdance.org.