Reputation: 57
I wonder if there is an equivalent load() of jQuery in GWT without using frames or any GWT framework.
I need to load a file .html in a div with GWT.
Something like this: RootPanel.get("content").add(page.html);
Any idea?
Upvotes: 0
Views: 203
Reputation: 26362
Add this: <inherits name="com.google.gwt.http.HTTP" />
to your gwt.xml file
Then you can do something with the HTML
widget and the RequestBuilder
For example
import com.google.gwt.http.client.*;
...
HTML htmlWidget = null;
String url = "http://www.myserver.com/getData?type=3";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
try {
Request request = builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
htmlWidget = new HTML(response.getText());
} else {
// Handle the error. Can get the status text from response.getStatusText()
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
}
if(htmlWidget!=null){
RootPanel.get("content").add(htmlWidget);
}
I could not see if it compiles (no access to an IDE at the moment) so excuse any minor errors you might need to correct.
Upvotes: 1
Reputation: 9537
There are several approaches documented here best way to externalize HTML in GWT apps?
I would prefer client bundle with a html resource in your scenario.
Upvotes: 0