使用UiBinder生成单元格

时间:2012-05-12 18:10:02

标签: gwt uibinder

GWT提供以下作为构建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);
      }
    }
  }

如果我有一个复杂的单元格,只需从render()返回一个安全的HTML字符串就变得单调乏味。有没有办法使用UiBinder,或者比手工构建HTML字符串更好?

1 个答案:

答案 0 :(得分:5)

GWT 2.5将完全为此目的添加UiRenderer:利用*.ui.xml模板构建渲染器,其中包含模板变量,能够在子元素上获取句柄renderered等。

等待GWT 2.5,您可以使用SafeHtmlTemplates,将模板拆分为单独的方法,然后将它们合成以构建您的单元格内容。

相关问题