How can I set id for GWT widgets in UiBinder?

怎甘沉沦 提交于 2019-11-27 16:44:49

问题


In java code we can set id. Is it possible to set 'id' for GWT widgets in UiBinder itself?

If it is possilbe please give me a sample.

Actually I tried the following code,

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

Then I checked it in alert. Window.alert("Id: " + login.getElement().getId()); But the output is Id:.

Id is not set for the login button

Is there any better way to do this?

Can anyone help me?

Thanks in advance, Gnik


回答1:


Check an availability of the following line in your module file (*.gwt.xml ):

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

And call the ensureDebugId(Element, id) method in your code:

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



回答2:


Adding ID is not possible. This problem is also filed as a bug report and closed as "as designed". For details, see:

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

But you can add a debugId if you add <inherits name="com.google.gwt.user.Debug"/> to your *.gwt.xml file.

See Mapping ui:field in GWT to generated code



来源:https://stackoverflow.com/questions/11845544/how-can-i-set-id-for-gwt-widgets-in-uibinder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!