I was confronted with this problem. How to retrieve Element references the body. As GWT API doesn’t provide this service directly you need to use an other way.
You can add for example an id to the body in the HTML description of the page
<html>
<head>
<meta name='gwt:module' content='fr.improve.testGWT.gwt.Application'>
</head>
<body id='bodyId'>
<script language="javascript" src="gwt.js"></script>
</body>
</html>
In your java application you just have to use the following code:
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
Element body= DOM.getElementById(« bodyId »);
Another solution is to use the JSNI with the following method:
public static native Element getBody() /*-{
return $doc.body;
}-*/;
The body element is retrieve with this call:
Element body = getBody();
And you don’t need to change the HTML page of your application.
It is a little bit strange that base element like the body can’t be directly accessible
