GWTQuery load() replaces element

79 views Asked by At

I am just getting started with GWTQuery, and am trying to wrap my head around the load() function. Consider:

    public void onModuleLoad() {
    SimplePanel sp = new SimplePanel();
    sp.getElement().setId("stuff");
    RootLayoutPanel root = RootLayoutPanel.get();
    root.add(sp);

    $("#stuff").load("/hello.html");
}

If I run the above, the empty div block for the SimplePanel element gets replaced with the contents of hello.html. In other words, it ends up in the body block, and the div disappears from the DOM. What I want is for the div block to contain hello.html. I worked around this by putting another temporary SimplePanel as the child of div id="stuff", and calling load() on that. It works as desired. But I get the feeling I am missing something fundamental. Is there a way to do this without the throwaway SimplePanel?

1

There are 1 answers

0
Manolo Carrasco Moñino On

Your coded works ok, GQuery load() replaces the content of the element with the stuff gotten from the server.

The implementation of load() as you can see in Ajax.java, first clean the returned string removing <html> <head> <body> and <script> tags, then wrap the content into a <div>, and finally empty the content of the target panel ($(#stuff) in your case), and appends the new created <div>.

I've tested your code with last snapshot and with stable versions, what release are you using?