我想加载“片段”的 HTML 来设置 HTMLPanels,它将通过获取 id 来动态修改,如下所示:
HTMLPanel dynContent = new HTMLPanel("<div id=\"test_id\"/>");
dynContent.add(new Label("This content is dynamically generated."), "test_id");
Run Code Online (Sandbox Code Playgroud)
我可以从 GWT 应用程序向我的客户端提供 HTML 文件吗(只加载在应用程序启动时提供的 html 文件会很酷)?或者我是否必须创建一个对服务器的调用来获取 HTML(比如 RPC)?听起来 JSP 是解决方案,但对于这样一个简单的应用程序,我宁愿远离它。
欢迎任何建议!
答案很简洁!我首先发现了这个: 在 GWT 应用程序中外部化 HTML 的最佳方法?
然后尝试通过 Client Bundle 加载静态数据:
public interface Resources extends ClientBundle {
Resources INSTANCE = GWT.create(Resources.class);
@Source("public/html/timesheet.html")
TextResource synchronous();
}
Run Code Online (Sandbox Code Playgroud)
然后我在我的 html 面板中加载资源:
HTMLPanel dynContent = new HTMLPanel(Resources.INSTANCE.synchronous().getText());
dynContent.add(new Label("This content is dynamically generated."), "dynContent");
simplePanel.add(dynContent);
Run Code Online (Sandbox Code Playgroud)
从我拥有的 HTML 文件中获取内容并根据需要填充 HTMLPanel。
| 归档时间: |
|
| 查看次数: |
3773 次 |
| 最近记录: |