For new Click projects please use Apache Click which is continuing the development of this framework.
table.add(new Column("name")).setSortable(true);If you created a custom Form, FieldSet or Table and overrode the add or addColumn method, you will be forced to return the methods argument. For example if you had:
form.add(new TextField("firstname")).setValue("Bob");
public class MyTable {you will need to update as follows:
public void addColumn(Column column) {
...
}
}
public class MyTable {
public Column addColumn(Column column) {
...
// You must return the column
return column;
}
}
Note these methods are still available on AbstractControl, so this change should have minimal impact on existing code bases.
If your created custom controls override toString(), please adapt it to the following pattern. From this:
public class HtmlTable extends AbstractControl {to this:
...
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();
}
}
public class HtmlTable extends AbstractControl {Note, the code between the commented section, was moved from toString to the render method.
...
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();
}
}
Also note that invoking a Control's toString() method still outputs the same HTML representation, as toString() delegates to the render method.
Please note a common problem when overriding render in custom components, is invoking super.toString() in order to render the Control's default markup:
public class CustomField extends Field {The highlighted line above will cause a StackOverflowError, meaning an infinite loop was encountered. The reason for the error will become obvious when tracing the sequence of calls:
...
public void render(HtmlStringBuffer buffer) {
String field = super.toString(); // BEWARE this line will cause StackOverflowError
...
}
public String toString() {
HtmlStringBuffer buffer = new HtmlStringBuffer();
render(buffer);
return buffer.toString();
}
}
The fix is straight forward. If you override a Control's render method, but still want to render the Control's default markup, invoke super.render instead of super.toString. Here is the correct version:
public class CustomField extends Field {
...
public void render(HtmlStringBuffer buffer) {
super.render(buffer); // NOTE StackOverflowError won't occur
...
}
public String toString() {
HtmlStringBuffer buffer = new HtmlStringBuffer();
render(buffer);
return buffer.toString();
}
}
It is possible to write your own LogService instance or extend from an existing implementation. To setup Click to use an alternative instance you have to specify the LogService implementation in click.xml:
<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().
Click 1.5 M2 introduced major enhancements to Control listener support.
public class MyPage extends Page {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 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;
}
});
}
}
See the section Deploying Custom Resources for more detail. [393].
Click 1.5 (currently in development) introduces important new features including:
The following is a list of enhancements and bugs fixes:
Click Framework now supports Exceptional Performance best practices for speeding up your web site. This filter combined with framework changes enable Click applications to get an Grade A rating with Yahoo's YSlow.
Panels are now rendered as $panel rather than #parse($panel)
Panels can now define Velocity templates on the classpath as well as the web file system.
Table control promoted to core net.sf.click.control.
Added Control methods getHtmlImports() and onDeploy().
This feature based on a concept developed by Ahmed Mohombe, and replaces the "msg:" prefix localization functionality introduced in release 0.13.
Refactored Menu to implement Control interface to improve Page subclassing.
Click team blogging application deployed on Tomcat 4.0 and Oracle 9i application servers.