gpt4 book ai didi

ajax - JSF 状态栏/连接状态信息

转载 作者:行者123 更新时间:2023-12-01 16:23:16 28 4
gpt4 key购买 nike

我想为我的用户实现一种关于进度状态的信息。我发现了几个组件,例如:

Richfaces statusIceFaces onnection Status

所以,我想在我的页面中添加类似的东西,特别是对于 ajax 请求。实现它的最简单方法是什么?我不想使用这些组件之一,而是自己编写一个,但我无法想象需要付出多少努力:-)

我很感激你的想法......

最佳答案

标准 JSF 实现没有为此提供现成的组件。 JSF 2.0 specification然而,第 13.3.5.2 章概述了以下内容:

13.3.5.2 Monitoring Events For All Ajax Requests

The JavaScript API provides the jsf.ajax.addOnEvent function that can be used to register a JavaScript function that will be notified when any Ajax request/response event occurs. Refer to Section 14.4 “Registering Callback Functions” for more details. The jsf.ajax.addOnEvent function accepts a JavaScript function argument that will be notified when events occur during any Ajax request/response event cycle. The implementation must ensure the JavaScript function that is registered must be called in accordance with the events outlined in Section TABLE 14-3 “Events”.



您可以找到 here Mojarra 开发人员之一的博客,其中包含基本示例。这是相关性的摘录:

<h3> Status:</h3>
<textarea id="statusArea" cols="40" rows="10" readonly="readonly" />

A simple textarea, not even hooked into the backend server data model.

Then in our javascript (for the demo, in a separately loaded file, though it could just as easily be in page) we have:

var statusUpdate = function statusUpdate(data) {
var statusArea = document.getElementById("statusArea");
var text = statusArea.value;
text = text + "Name: "+data.source.id;
if (data.type === "event") {
text = text +" Event: "+data.name+"\n";
} else { // otherwise, it's an error
text = text + " Error: "+data.name+"\n";
}
statusArea.value = text;
};

// Setup the statusUpdate function to hear all events on the page
jsf.ajax.addOnEvent(statusUpdate);
jsf.ajax.addOnError(statusUpdate);

关于ajax - JSF 状态栏/连接状态信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3556676/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com