我想加载HTML的“片段”来设置HTMLPanels,它将通过获取id来动态修改,如下所示:
HTMLPanel dynContent = new HTMLPanel("<div id=\"test_id\"/>");
dynContent.add(new Label("This content is dynamically generated."), "test_id");
我可以从GWT应用程序向我的客户端提供HTML文件(加载应用程序启动时提供的html文件会很酷吗?)或者我是否必须创建对服务器的调用以获取HTML(比如RPC)?听起来JSP就是解决方案,但我宁愿远离这个这么简单的应用程序。
欢迎任何建议!
答案 0 :(得分:4)
答案非常简洁!我第一次发现这个: best way to externalize HTML in GWT apps?
然后尝试通过Client Bundle加载静态数据:
public interface Resources extends ClientBundle {
Resources INSTANCE = GWT.create(Resources.class);
@Source("public/html/timesheet.html")
TextResource synchronous();
}
然后我在html面板中加载资源:
HTMLPanel dynContent = new HTMLPanel(Resources.INSTANCE.synchronous().getText());
dynContent.add(new Label("This content is dynamically generated."), "dynContent");
simplePanel.add(dynContent);
获取我所拥有的HTML文件中的内容,并根据需要填充HTMLPanel。