aspose file tools*
The moose likes GWT and the fly likes how to get HTML div id name from RootPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "how to get HTML div id name from RootPanel" Watch "how to get HTML div id name from RootPanel" New topic
Author

how to get HTML div id name from RootPanel

Tadas Davidsonas
Greenhorn

Joined: Aug 17, 2010
Posts: 9
When generating divs dynamically I need to add some content to them. And for that I need to know the divs id. I can get the div element using for example:




But how to get id from the div element?

For example inside the "mainBox" div I have the structure like this:

<div id=topTest align=left>
<div id=test1 align=center></div>
<div id=test2 align=center></div>
<div id=test3 align=center></div>
</div>
<div id=bottomTest align=left>
<div id=test4 align=center></div>
<div id=test5 align=center></div>
</div>

And I want to get all the div id's where inside topTest and bottomTest?

Any suggestions?

Thank you
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

Tadas Davidsonas wrote:When generating divs dynamically


First of all, I need to know a bit more about your problem,
are you mixing GWT with another technology ?

Reason for asking that is if Divs are generated dynamically in pure GWT, they are a part of your GWT code.
This means that the HTML page would be static, and you can hard code stuff like:


On a side note:
1. GWT has a ensureDebugId method to set a id to an element.
2. This code generates the same output :



My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Tadas Davidsonas
Greenhorn

Joined: Aug 17, 2010
Posts: 9
Thank you for the suggestion. But still gwt complains for some reason.
If I code like this:



Gwt complains:

09:59:30.137 [ERROR] [smart] Uncaught exception escaped java.lang.AssertionError: A widget that has an existing parent widget may not be added to the detach list at com.google.gwt.user.client.ui.RootPanel.detachOnWindowClose(RootPanel.java:136) at com.google.gwt.user.client.ui.RootPanel.get(RootPanel.java:211) at com.bct.smart.client.Template$2.onResponseReceived(Template.java:192) at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287) at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393) at sun.reflect.GeneratedMethodAccessor125.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157) at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.core.client.impl.Impl.apply(Impl.java) at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188) at sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157) at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222) at java.lang.Thread.run(Unknown Source)


It adds a button successfully using(But click handler do not works):



ids are created and added dynamically everytime using gwt like this:



Kind regards,
Tadas

Tadas Davidsonas
Greenhorn

Joined: Aug 17, 2010
Posts: 9
Revomed html adding and added this instead:



But how apply style to the id if instead of id = test, it adds id = gwt-debug-test1. And the #gwt-debug-test1 or .gwt-debug-test1 just do not works?
Tadas Davidsonas
Greenhorn

Joined: Aug 17, 2010
Posts: 9
panel.addStyleName("testuojam"); works but I need to load the styles dynamically from file. I used



But it worked ok only with
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get HTML div id name from RootPanel