Generating Cells with UiBinder

The following is an example of cell construction for CellListGWT:

  /**
   * A simple data type that represents a contact.
   */
  private static class Contact {
    private static int nextId = 0;

    private final int id;
    private String name;

    public Contact(String name) {
      nextId++;
      this.id = nextId;
      this.name = name;
    }
  }

  /**
   * A custom {@link Cell} used to render a {@link Contact}.
   */
  private static class ContactCell extends AbstractCell<Contact> {
    @Override
    public void render(Context context, Contact value, SafeHtmlBuilder sb) {
      if (value != null) {
        sb.appendEscaped(value.name);
      }
    }
  }

If I have a complex cell, just returning a safe HTML string from render()becomes tedious. Is there a way to use UiBinder for this, or is something better than manually creating an HTML string?

+3
source share
1 answer

GWT 2.5 will add UiRendererjust for this purpose: using a template *.ui.xmlto create a renderer, with template variables, the ability to get a sub-element descriptor for rendering, etc.

While waiting for GWT 2.5, you can use SafeHtmlTemplatesit by breaking your template into separate methods and then composing them to create the contents of the cells.

+5
source

All Articles