Load HTML document to populate HTMLPanel a good idea?

感情迁移 提交于 2020-01-13 06:29:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!