Gwt 用UiBinder生成单元

Gwt 用UiBinder生成单元,gwt,uibinder,Gwt,Uibinder,GWT提供以下内容作为为单元列表构建单元的示例: /** * 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) { n

GWT提供以下内容作为为
单元列表构建单元的示例:

  /**
   * 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);
      }
    }
  }
/**
*表示联系人的简单数据类型。
*/
私有静态类联系人{
私有静态int nextId=0;
私有最终int id;
私有字符串名称;
公共联系人(字符串名称){
nextId++;
this.id=nextId;
this.name=名称;
}
}
/**
*用于呈现{@link Contact}的自定义{@link Cell}。
*/
私有静态类ContactCell扩展了AbstractCell{
@凌驾
公共void呈现(上下文上下文、联系人值、SafeHtmlBuilder sb){
if(值!=null){
某人(价值、姓名);
}
}
}

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

GWT 2.5将添加
UiRenderer
,正是为了实现这一目的:利用
*.ui.xml
模板来构建渲染器,使用模板变量,在渲染时能够获得子元素的句柄,等等

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