定期刷新 Tapestry 区域

发布于 2024-07-25 14:02:50 字数 44 浏览 2 评论 0原文

定期刷新 Tapestry 区域以从服务器提取数据集更改的最佳方法是什么?

What is the best way to refresh a Tapestry zone on a regular basis to pull changes of a dataset from a server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柏林苍穹下 2024-08-01 14:02:50

首先,您需要公开事件处理程序的 url:

public String getModeChangedUrl()
{
    // will call the onModeChanged method
    return resources.createEventLink("ModeChanged").toAbsoluteURI();
}

然后,在 tml 中的 javascript 块中将 url 分配给变量:

var modeChangedUrl = "${modeChangedUrl}";

然后您需要获取 ZoneManager javascript 对象的句柄:

var zm = Tapestry.findZoneManagerForZone(zoneId);

您所在的区域并不重要获取ZoneManager,这一切都是为了促进ajax回调。 如果事件侦听器返回 MultiZoneUpdate 或不同区域的更新,它将被正确处理。

我使用虚拟区域进行编组,并且始终返回 MultiZoneUpdate,即使我只更新一个区域。 由于我经常需要更新多个区域,因此我发现更容易保持我的方法的一致性。 无论如何,这对于您的问题来说有点偏离主题。

如果您有事件处理程序的其他参数,您可以将它们附加到以“/”分隔的网址,即“http://www.host.com/” app/page/event/param1/param2"

现在您已经有了 urlZoneManager,您可以初始化请求-响应循环:

zm.updateFromURL(url);

正如 henning 建议的那样,将其与原型中的 PeriodicalExecuter 将实现您想要的:

new PeriodicalExecuter(function(pe)
    {
        var zm = Tapestry.findZoneManagerForZone("anyZoneId");
        zm.updateFromUrl(url);
    }, 5);

Firstly, you'll need to expose the url for your event handler:

public String getModeChangedUrl()
{
    // will call the onModeChanged method
    return resources.createEventLink("ModeChanged").toAbsoluteURI();
}

Then, in a javascript block in your tml assign the url to a variable:

var modeChangedUrl = "${modeChangedUrl}";

Then you need to get a handle to a ZoneManager javascript object:

var zm = Tapestry.findZoneManagerForZone(zoneId);

It's not important which zone you get the ZoneManager for, all this does is facilitate the ajax callback. If the event listener returns a MultiZoneUpdate or an update for a different zone, it will be handled correctly.

I use a dummy zone for marshalling and always return a MultiZoneUpdate even if I'm only updating one zone. Since more often than not I need to update multiple zones, I find it easier to be consistent in my approach. anyway, that is a little off topic for your question.

if you have additional parameters for the event handler, you can append them to the url separated by '/' ie "http://www.host.com/app/page/event/param1/param2"

now that you have the url and a ZoneManager, you can initialise the request-response loop:

zm.updateFromURL(url);

as henning suggested, combining this with the PeriodicalExecuter in prototype will achieve what you want:

new PeriodicalExecuter(function(pe)
    {
        var zm = Tapestry.findZoneManagerForZone("anyZoneId");
        zm.updateFromUrl(url);
    }, 5);
一江春梦 2024-08-01 14:02:50

您可以使用 Prototype 的 PeriodicalExecuter,并调用 Tapestry 的 ZoneManager 来更新区域:

new PeriodicalExecuter(function(pe) {
    var zoneObject = Tapestry.findZoneManager(element);
    zoneObject.updateFromUrl(updateUrl);
}, 5);

You could use Prototype's PeriodicalExecuter, and have that call Tapestry's ZoneManager to update the zone:

new PeriodicalExecuter(function(pe) {
    var zoneObject = Tapestry.findZoneManager(element);
    zoneObject.updateFromUrl(updateUrl);
}, 5);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文