开发者

AJAX delay on richfaces tree selection

I have a JSF 2 application which uses a Richfaces 4 tree control. The tree is set to use the "AJAX" switch type. On each selection an AJAX call is made to the server to update the selection value of the tree's backing 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.

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. Has anyone else tried something similar? Am I going to have to find the pa开发者_如何学JAVArent div and work down to the second span? 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".


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. However, we still had a requirement to store the current selection state in the tree's backing bean. To do so, I added an a4j:jsfunction to the page ...

<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="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.

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. Unfortunately "onselected" doesn't seem to be implemented in the current milestone build.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜