【问题标题】:How can I set id for GWT widgets in UiBinder?如何在 UiBinder 中为 GWT 小部件设置 id?
【发布时间】:2012-08-04 10:38:02
【问题描述】:

在java代码中我们可以设置id。是否可以在 UiBinder 本身中为 GWT 小部件设置“id”?

如果可以,请给我一个样品。

其实我试过下面的代码,

<g:Button ui:field="login" debugId="loginButton">

然后我在警报中检查了它。 Window.alert("Id: " + login.getElement().getId()); 但输出是Id:

没有为登录按钮设置 ID

有没有更好的方法来做到这一点?

谁能帮帮我?

提前致谢, 格尼克

【问题讨论】:

    标签: gwt uibinder gwt2


    【解决方案1】:

    无法添加 ID。 此问题也作为错误报告提交,并按“设计”关闭。详情见:

    http://code.google.com/p/google-web-toolkit/issues/detail?id=4176

    但你可以添加一个 debugId 如果你添加 &lt;inherits name="com.google.gwt.user.Debug"/&gt; 到您的 *.gwt.xml 文件中。

    Mapping ui:field in GWT to generated code

    【讨论】:

      【解决方案2】:

      检查模块文件 (*.gwt.xml) 中以下行的可用性:

      <inherits name="com.google.gwt.user.Debug"/> 
      

      并在您的代码中调用ensureDebugId(Element, id) 方法:

      login.ensureDebugId(login.getElement(), "loginButton");
      

      【讨论】:

      • 继承了Debug模块,你也可以像一样使用uiBinder.xml中的debugId属性.要删除 gwt-debug 前缀,请在 onModuleLoad() 中调用 DebugInfo.setDebugIdPrefix("")。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 2011-07-04
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      相关资源
      最近更新 更多