问题
I want to load "pieces" of HTML to set HTMLPanels which will be dynamically modified by getting the id's as follows:
HTMLPanel dynContent = new HTMLPanel("<div id=\"test_id\"/>");
dynContent.add(new Label("This content is dynamically generated."), "test_id");
Can I serve HTML files to my client from a GWT app (It would be cool to just load the html files served at application startup)? Or do I have to create a call to the server to get the HTML (say RPC)? It sounds like JSP is the solution but I rather stay away from this for such a simple app.
Any suggestions are welcome!
回答1:
The answer is pretty neat! I first found this: best way to externalize HTML in GWT apps?
Then tried this to load static data via Client Bundle:
public interface Resources extends ClientBundle {
Resources INSTANCE = GWT.create(Resources.class);
@Source("public/html/timesheet.html")
TextResource synchronous();
}
Then I load the resources in my html panel:
HTMLPanel dynContent = new HTMLPanel(Resources.INSTANCE.synchronous().getText());
dynContent.add(new Label("This content is dynamically generated."), "dynContent");
simplePanel.add(dynContent);
The content from the HTML file I have is fetched and populates the HTMLPanel as I wanted.
来源:https://stackoverflow.com/questions/5837633/load-html-document-to-populate-htmlpanel-a-good-idea