如何在UiBinder中为GWT小部件设置id?

8
在Java代码中,我们可以设置ID。在UiBinder中是否有可能为GWT小部件设置“id”?
如果可能的话,请给我一个示例。
实际上,我尝试了下面的代码:
<g:Button ui:field="login" debugId="loginButton">

然后我在提示框中检查了它。 window.alert("Id: " + login.getElement().getId()); 但输出结果为Id:

登录按钮的ID未设置

有更好的方法吗?

有人能帮帮我吗?

提前致谢, Gnik

2个回答

9

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

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

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

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

1
继承Debug模块后,您还可以在uiBinder.xml中使用debugId属性,例如<g:HTMLPanel debugId="test">。默认情况下,元素ID将变为gwt-debug-test。要删除gwt-debug前缀,请在onModuleLoad()中调用DebugInfo.setDebugIdPrefix("")。 - David Chandler

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接