简体   繁体   English

Richfaces树选择的AJAX延迟

[英]AJAX delay on richfaces tree selection

I have a JSF 2 application which uses a Richfaces 4 tree control. 我有一个使用Richfaces 4树控件的JSF 2应用程序。 The tree is set to use the "AJAX" switch type. 树设置为使用“ AJAX”开关类型。 On each selection an AJAX call is made to the server to update the selection value of the tree's backing bean. 在每次选择时,都会对服务器进行AJAX调用,以更新树的后备bean的选择值。

On clicking a node there is a delay between the click and the node appearing as selected. 单击节点时,在单击和节点显示为选定状态之间存在延迟。 The documentation does state that using this method may cause a slight delay, but I wonder why it doesn't just update the style of the node before issuing the AJAX request, so that the user isn't left wondering if the click has been registered. 文档确实指出使用此方法可能会引起一些延迟,但是我想知道为什么它不仅仅发出AJAX请求之前更新节点的样式,这样用户就不会怀疑单击是否已被注册。 。

I've been trying to figure out a way to update the node on a javascript onclick event, but I don't see an id on the span that I'd have to change. 我一直在试图找到一种方法来更新javascript onclick事件上的节点,但是我没有看到必须更改的范围上的ID。 Has anyone else tried something similar? 有没有其他人尝试过类似的东西? Am I going to have to find the parent div and work down to the second span? 我是否必须找到父div并向下工作到第二个跨度? Surely there's a better way? 当然有更好的方法吗?

Note that using the "client" switch type is not an option, as we need to be able to query for child nodes dynamically. 请注意,不能选择使用“客户端”开关类型,因为我们需要能够动态查询子节点。 Building the entire tree in one go is not practical in this instance, so it has to be either "server" or "Ajax". 在这种情况下,一次性构建整个树是不实际的,因此它必须是“服务器”或“ Ajax”。

Answering my own question - and contradicting my "no client switching" stipulation a little bit. 回答我自己的问题-与我的“禁止客户切换”规定有点矛盾。

Since we're using RichFaces 4, I'm able to specify that tree node expansion should use ajax (allowing the tree to be populated "lazily"), and selection should be client-side only. 由于我们使用RichFaces 4,因此我可以指定树节点扩展应使用ajax(允许“懒惰地”填充树),并且选择应仅在客户端进行。 However, we still had a requirement to store the current selection state in the tree's backing bean. 但是,我们仍然需要将当前选择状态存储在树的支持bean中。 To do so, I added an a4j:jsfunction to the page ... 为此,我在页面上添加了a4j:js函数...

<a4j:jsFunction name="onSelection">
    <a4j:param name="param1" assignTo="#{treeBean.selectedNodeID}"  />    
</a4j:jsFunction>

... and called it from the "onmousedown" event on each tree node ... ...并从每个树节点上的“ onmousedown”事件中调用它...

onmousedown="onSelection('#{node.id}')"

This way the tree updates visually without waiting for the ajax request to complete, and feels a lot snappier to the user. 这样一来,树就可以直观地更新,而无需等待ajax请求完成,并且使用户感觉更加敏捷。

The only problem with this seems to be that the onmousedown event is fired when clicking on the toggle as well, so expanding a node causes it to be "selected" without updating its style. 唯一的问题似乎是在单击切换开关时也会触发onmousedown事件,因此展开节点会导致其被“选中”而不更新其样式。 Unfortunately "onselected" doesn't seem to be implemented in the current milestone build. 不幸的是,在当前的里程碑版本中似乎没有实现“ onselected”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM