问题
I would like to know what the rootPanel
(which is in the entryClass) exactly is, and how GWT loads the Java code into the appname.html file via rootpanel.
What happens there exactly?
Where is the connection between the rootpanel and the HTML file?
I could not find any side which explains this process in a detail. It would be very helpful if somebody could explain it or send some good links to websites which are explaining this issue.
回答1:
Have you checked the sources for RootPanel
class?
There is a method RootPanel get(String id)
that returns element (well, widget) from the page depending on the element id you pass in. If you don't pass anything and for example ask for get()
or get(null)
you will receive <body>
as your requested RootPanel instance.
So, you have your index.html with contents:
<body>
<div id="myPanel"></div>
</body>
in it.
In onModuleLoad()
method of your entry class you do
FlowPanel myNewDiv = new FlowPanel();
// add some styles, more elements and event handlers to myNewDiv
// ...
RootPanel.get("myPanel").add(myNewDiv);
Which adds your new div as a child to myPanel
div which was originally in the html file.
Did this help?
来源:https://stackoverflow.com/questions/13923716/how-does-gwt-work-or-rather-how-does-gwt-load-the-code-into-the-app-html-file