How can I set id for GWT widgets in UiBinder?
Asked Answered
M

2

8

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

Minardi answered 7/8, 2012 at 12:3 Comment(0)
U
9

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");
Upstate answered 7/8, 2012 at 13:57 Comment(1)
With the Debug module inherited, you can also use the debugId attribute in uiBinder.xml like <g:HTMLPanel debugId="test"> By default, the element ID will then be gwt-debug-test. To remove the gwt-debug prefix, call DebugInfo.setDebugIdPrefix("") in your onModuleLoad().Fimble
B
4

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

Belfry answered 9/8, 2012 at 6:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.