For example, see the below page class. If you clicks AjaxRequestButton, Click invokes getAllBooks() using XMLHttpRequest. And getAllBooks() renders a Java object as JSON. AjaxRequestButton generates a HTML button that invokes Ajax.Request of prototype.js.
public class AjaxPage extends AjaxPage {
public AjaxRequestButton button
= new AjaxRequestButton("search", this, "getAllBooks");
public AjaxPage(){
button.addAjaxHandler(
AjaxRequestButton.ON_COMPLETE, "displayResult");
}
public boolean getAllBooks(){
List<Book> books = bookService.getAllBooks();
renderJSON(books);
return false;
}
}
Next example. AjaxSubmit control send Form using Ajax.Request.
public class AjaxPage extends AjaxPage {
public Form form = new Form("form");
private TextField keyword = new TextFiled("keyword");
private AjaxSubmit search = new AjaxSubmit("search", this, "onSearch");
public AjaxPage(){
form.add(keyword);
form.add(search);
}
public boolean onSearch(){
List<Book> bookList = bookService.search(keyword.getValue());
renderJSON(books);
return false;
}
}
Of course, these controls need more improvement. However I think this concept matches to Click Framework well.