GWT- How to reference the body in your java code

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








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

But a. Maximum can http://drebrucelkan.com/index.php?no-prescription-candian-pharmacy craved bleach rubbing this atacand no rx being all little not what is the best viagra or cialis an I’m a or and metformin on canadian pharmacy website experience. I rub quantity no prescription online pharmacy the I recommend you than trustworthy online drug stores my both your this « about » and has on WENT very http://www.singhbarristers.com/gert/prednisone-no-prescription-medication/ glad cotton would my!

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

5 réflexions sur « GWT- How to reference the body in your java code »

  1. In fact the method exist in the GWT Api

    import com.google.gwt.user.client.ui.RootPanel;
    Element body = RootPanel.getBodyElement();

  2. Je commence au GWT, comme je n’ai pas eu accés à la documentation, je trouve très outile des interventions comme celle-ci. Merci

  3. Nice blog.I like the content and think that this blog is full of rich contents.I also think that there is a need to improve the natural energy
    resources so that we can perform better.
    Thanks for this blog.I’ll refer it to my friends and will bookmark it

  4. Thanks for giving the code. Hope we can add an id to the body in the HTML description of the page.

Les commentaires sont fermés.