-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello, on project I migrated from ZK5 to ZK8 and I found unusual behaviour of Treeitem event and render methods.
I am using:
zul - 8.0.11
zkplus - 8.0.11
zkbind - 8.0.111
zk - 8.0.11
On ZK5 it was working like this:
render() every treeitem that is on the first level from root. ( treeitem listener added in overriden render method. )
When I am clicking on treeitem to expand it, render() called once more and only after it ZK calling onOpen event.
On ZK8 it was working like this:
render() every treeitem that is on the first level from root. ( treeitem listener added in overriden render method. )
When I am clicking on treeitem to expand it, ZK calling onOpen event and after renders new row (that row that should be expanded).
My problem is: In render() I am setting value for each treeitem. So, as if in ZK8 I am getting event before render() and I am stuck in situation when treeitem has no value.
Please give some piece of advice, where should I go. I saw org.zkoss.zk.ui.impl.UiVisualizer.TimedValue class. And there are some timings for events executions. Is it related to my problem? Because I noticed that in ZK5 I had _timed = 75 for onOpen and in ZK8 - _timed = 3.
Hi Dgray,
I can't verify the difference (between ZK 5 and 8) based on your description. I created a runnable example on ZK Fiddle.
You can test it using various ZK versions, I compared the event sequence between ZK 5 and ZK 8. In both cases the children are first rendered, and then the onOpen event is fired.
Assuming your usage is different: Can you please adjust the example to match your scenario. Or maybe my example just works in your case, just let me know.
Robert
Thanks for the hint. I made new project from Maven archetype, put inside code from your ZK Fiddle example. But it works as I mentioned before.
Attaching screenshot: s4.postimg.org/gd4clvrlp/20160819_171601.jpg
I am using Java 8u92
I am guessing here a bit (since you didn't mention it): Using the open source CE version (instead of EE) I can see the same sequence of events you describe. (the java version won't make a difference here)
TimedValue's are used to order responses to the client, and have no effect on the event sequence at the server side.
To give you a suggestion how to avoid problems like that I'd need some information on the purpose of retrieving the value, because the values are easily accessible from your TreeModel. At the moment I don't see the need to get the value from a TreeItem itself. Can you be more specific there, and provide an example showing the purpose of doing that or at least the idea behind it?
Besides, if you need to do something "later" you can always listen to a custom event and post(queue) an event to yourself to execute later:
e.g. in your onOpen listener post this event to yourself:
Events.postEvent("onAfterNodeOpen", mycomponent, mydata);
https://www.zkoss.org/wiki/ZKDeveloper'sReference/EventHandling/EventFiring
About events firing. I tried it before, but situation still same: onOpenEvent -> onAfterNodeOpened -> render().
private void addExpandedListener(final Treeitem item, final LoadTimeLine line) {
item.addEventListener("onOpen", event -> Events.postEvent("onAfterNodeOpened", item, line));
item.addEventListener("onAfterNodeOpened", event -> {
if ( "onAfterNodeOpened".equals(event.getName()) ) {
System.out.println("onAfterNodeOpened");
} else {
System.out.println("Else");
}
});
}
this method I am calling in TreeitemRenderer:
private TreeitemRenderer getRendererForTree() {
return new TreeitemRenderer() {
@Override
public void render(Treeitem treeitem, Object o, int index) throws Exception {
//...
addExpandedListener(treeitem, line);
//...
}
About purpose of doing it. In onOpen event I need to know how many treeitems ( that refers to parent I clicked on ) are closed.
So, when I am searching values and children of nested items, I am facing nulls, because children of that item will be rendered a little bit later. And about TreeModel, in my case we are implementing own version of AbstractModelTree, and we have no strict bound between ZK component and data.
Asked: 2016-08-09 09:24:40 +0800
Seen: 48 times
Last updated: Sep 02 '16
How to control selectAll() feature in a Listbox with multiple=true and checkmark=true
ZK8 Wizard Series: Part 2 now released!
Faster And Lighter, The Performance Test On ZK8
org.zkoss.xel.XelException: Resource not found: http://www.zkoss.org/dsp/web/core
How To Check Dirty Status in ZK8?
Come and join the ''JS'' Hunt!