Annotation Interface GridColumn


@Retention(RUNTIME) @Target(METHOD) @Documented public @interface GridColumn
Declare a Grid.Column to be auto-generated by a GridColumnScanner.

This annotation annotates methods in a model class T that backs a Grid<T>. When the class is scanned by a GridColumnScanner, each annotation results in a corresponding Grid.Column being added to the Grid under construction, configured according to the various annotation properties.

The annotated method is often a bean property getter method, but this is not required.

Rendering

By default, the method's return value is used to render the column by simple conversion to a String. Custom rendering is possible by specifying a renderer(), or by having the method return a Component directly; see renderer() for details;

Some examples:


 // Container backing object class
 public class User {

     // Default rendering using String value
     @GridColumn(header = "Username", width = "50px")
     public String getUsername() { ... }

     // Custom rendering based on property value using MyDobRenderer
     @GridColumn(header = "DOB", sortable = true, renderer = MyDobRenderer.class)
     public LocalDate getDateOfBirth() { ... }

     // Custom rendering based on the entire backing object
     @GridColumn(header = "✔︎", renderer = SelectedRenderer.class)
     public void selectedColumn() { ... }

     // Method directly returns a Component to be displayed
     @GridColumn(header = "Status")
     public Image statusColumn() { ... }
 }

 // Build Grid with auto-generated columns
 final Grid<User> grid = new GridColumnScanner<>(User.class).buildGrid();
 ...

 

Some details regarding @GridColumn annotations:

  • Annotated methods must be instance methods taking zero parameters; annotations on other methods are ignored.
  • Protected, package private, and private methods are supported (assuming they are accessible).
  • @GridColumn annotations declared in super-types (including interfaces) are supported
  • If a method and the superclass or superinterface method it overrides are both annotated with @GridColumn, then the overridding method's annotation takes precedence (all properties are overridden).
  • If two methods with different names are annotated with @GridColumn for the same column key, then the declaration in the class which is a sub-type of the other wins (if the two classes are equal or not comparable, an exception is thrown). This allows subclasses to "override" which method supplies a given property.
  • If the method returns a sub-type of Component, then by default a SelfRenderer is assumed. This lets you define a method that directly returns the Component to display.
  • If the annotated methods return void or Void, then a renderer() is required and it must have a default constructor.
  • Columns will be ordered first by order(), then by property name.
See Also: