JSF状态栏/连接状态信息状态栏、状态、信息、JSF

2023-09-10 13:48:17 作者:心如薄荷天然凉

我想实现一种信息为我的用户有关的进展情况。我已经发现了几个组件,如:

RichFaces的状态或< A HREF =htt​​p://component-showcase.icefaces.org/component-showcase/showcase.iface相对=nofollow> ICEfaces的onnection状态

所以,我想类似的东西添加到我的网页特别是对于Ajax请求。什么是实现它的最简单的方法是什么?我不喜欢使用其中的一个组成部分,而不是编程我自己一个人,但我怎么也想不到,有多少精力花费: - )

我是心存感激的想法......

解决方案

标准的JSF实现不为此提供了一个现成的应用组件。该 JSF 2.0规范然而概述了章13.3.5.2以下内容:

  

13.3.5.2监测活动对于所有的Ajax请求

     

此外,JavaScript API提供了 jsf.ajax.addOnEvent 的功能,可用于注册一个JavaScript函数   当任何Ajax请求/响应事件发生时将得到通知。请参阅14.4节注册回调   功能的更多细节。该 jsf.ajax.addOnEvent 函数接受一个JavaScript函数的参数,这将是   通知时,在任何Ajax请求/响应事件循环发生的事件。实现必须   确保被注册,必须调用按照概述的事件JavaScript函数   第表14-3事件。

您可以找到这里的Mojarra开发,其中包含基本的例子之一的博客。以下是相关的摘录:

 &LT; H3&GT;状态:其中,/ H3&GT;
&LT; textarea的ID =statusAreaCOLS =40行=10只读=只读/&GT;
 
如何查看win7资源管理器状态栏

有一个简单的文本区域,甚至没有上钩   到后端服务器的数据模型。

     

然后,在我们的JavaScript(用于演示,   在一个单独加载的文件,但它   可以很容易地在页面),我们   有:

  VAR statusUpdate =功能statusUpdate(数据){
    变种statusArea =的document.getElementById(statusArea);
    VAR文本= statusArea.value;
    文=文+姓名:+ data.source.id;
    如果(data.type ===事件){
        文=文+事件:+ data.name +\ N的;
    }其他{//否则,它是一个错误
        文=文+错误:+ data.name +\ N的;
    }
    statusArea.value =文本;
};

//设置的statusUpdate功能听到网页上的所有事件
jsf.ajax.addOnEvent(statusUpdate);
jsf.ajax.addOnError(statusUpdate);
 

I would like to implement a kind of information for my users about the progress status. I have found several components like:

Richfaces status or IceFaces onnection Status

So, I would like to add something like that to my page especially for ajax requests. What's the easiest way to implement it? I would not like to use one of those components, rather programming my own one but I can't imagine how and how much effort it takes :-)

I am thankfull for ideas...

解决方案

The standard JSF implementation doesn't provide a ready-to-use component for this. The JSF 2.0 specification however outlines the following in chapter 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".

You can find here a blog of one of the Mojarra developers which contains basic examples. Here's an extract of relevance:

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