public class MyPage extends Page {
public void onInit() {
Submit submit = new Submit("submit");
submit.setActionListener(new ActionListener() {
public boolean onAction(Control source) {
// Perform submit action and return true to continue processing
return true;
}
});
}
}
Note that the source Control is passed in as an argument to the onAction method.
For very complex scenarios it is useful to know which Control triggered the event
[369].
public class HtmlTable extends AbstractControl {
...
public String toString() {
int estimatedControlSize = 1000;
HtmlStringBuffer buffer = new HtmlStringBuffer(estimatedControlSize);
// Rendering Start
buffer.elementStart("table");
appendAttributes(buffer);
buffer.elementClose();
renderRows(buffer);
buffer.closeElement("table");
// Rendering End
return buffer.toString();
}
}
to this:
public class HtmlTable extends AbstractControl {
...
public void render(HtmlStringBuffer buffer) {
// Rendering Start
buffer.elementStart("table");
appendAttributes(buffer);
buffer.elementClose();
renderRows(buffer);
buffer.closeElement("table");
// Rendering End
}
public String toString() {
int estimatedControlSize = 1000;
HtmlStringBuffer buffer = new HtmlStringBuffer(estimatedControlSize);
render(buffer);
return buffer.toString();
}
}
Note, the code between the commented section, was moved from toString to the render method.
Also note that invoking a Control's toString()
method still outputs the same HTML representation, as toString() delegates to the
render
method.
<click-app charset="UTF-8">
<pages package="net.sf.click.examples.page"/>
<log-service classname="net.sf.click.extras.service.JdkLogService"/>
</click-app>
While it is generally not recommended to use the Click LogService in your application code, you can retrieve it using the ClickUtils method
getLogService().