加载HTML文档以填充HTMLPanel是一个好主意吗? [英] Load HTML document to populate HTMLPanel a good idea?

查看:132
本文介绍了加载HTML文档以填充HTMLPanel是一个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载HTML的片段"以设置HTMLPanels,这些HTMLPanels将通过获取id来动态修改,如下所示:

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");

我可以从GWT应用程序向客户端提供HTML文件吗(仅加载在应用程序启动时提供的html文件会很酷)?还是我必须创建对服务器的调用才能获取HTML(例如RPC)?听起来JSP是解决方案,但对于这样一个简单的应用程序,我宁愿不要这样做.

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.

欢迎提出任何建议!

推荐答案

答案非常简洁!我首先发现了这一点: 在GWT应用程序中将HTML外部化的最佳方法?

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();

}

然后我在html面板中加载资源:

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); 

从我拥有的HTML文件中获取内容,并根据需要填充HTMLPanel.

The content from the HTML file I have is fetched and populates the HTMLPanel as I wanted.

这篇关于加载HTML文档以填充HTMLPanel是一个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆