Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Cells with UiBinder

Tags:

gwt

uibinder

GWT provides the following as an example of building cells for a CellList:

  /**
   * 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, simply returning a safe HTML string from render() becomes tedious. Is there a way to use UiBinder for this, or anything better than building the HTML string by hand?

like image 224
Nick Heiner Avatar asked Apr 20 '26 10:04

Nick Heiner


1 Answers

GWT 2.5 will add UiRenderer exactly for that purpose: leveraging an *.ui.xml template to build a renderer, with template variables, ability to get a handle on a subelement when renderered, etc.

Pending GWT 2.5, you can use SafeHtmlTemplates, splitting your template into separate methods and then compositing them to build your cell's content.

like image 153
Thomas Broyer Avatar answered Apr 28 '26 09:04

Thomas Broyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!