0

Difference between @load() and ${}

asked 2017-12-18 16:50:32 +0800

adilov gravatar image adilov
3 1

Hello everyone, I have a question about value loading in the .zul files. What's the difference between @load() and ${}?

What I found is that with $, the casting for the lists does not work, for example when loading values for listbox or combobox. The other and not so obvious thing is that every value that has been loaded with $ cannot be "updated" using "@NotifyChange" annotation from the java/view model part. These two work fine with @load.

Is there a benefit to use ${} instead of @load() when loading something that wont change in some point of usage, e.g. dropdown menus, etc?

Thank you :)

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2017-12-18 22:27:24 +0800

chillworld gravatar image chillworld flag of Belgium
5153 3 9
https://github.com/chillw...

updated 2017-12-18 22:32:24 +0800

${} and @init() are more equal then ${} and @load() in your question.
The ${} is a static reference, who if filled in at another time then the MVVM annotations.
Indeed, it's not a MVVM annotations and also static, so loaded once, never change again.
The @init is almost the same loaded once, never change again expect if you are working with the if attribute of a component.
There will work only the ${} because the if is evaluated before the whole MVVM.

Hope this clears enough.

link publish delete flag offensive edit

answered 2017-12-22 13:52:10 +0800

adilov gravatar image adilov
3 1

Hi, sorry for the late reply, as a new user I couldn't post a new answer sooner than 2 days after my first one...

This useful information, thank you! Is there any performance (or other?) benefit to use the static reference ${} instead of @init or @load when the value is needed only for displaying purposes? E.g. faster, lighter?

link publish delete flag offensive edit

answered 2017-12-22 15:28:03 +0800

cor3000 gravatar image cor3000
3669 1 7
ZK Team

the static expressions ${} are definitely more-lightweight than the data-binding annotations @load/@init.

${} expressions are replaced almost instantly when the zul is parsed and components are created and no additional mechanics will change them later.

Annotations are parsed as well but only added as meta information to a component (consumes a bit memory). A bit later, when the BindComposer kicks in it will find those annotations and evaluate them - @init() only once, @load() will evaluate initially and again on notify-change or conditional @load(... after/before='command'). This kind of Bind tracking requires additional memory and processing overhead. So if not needed don't use @load and prefer @init or ${}.

A bit similar topic was mentioned in one of our dos and don'ts articles.

short answer: cheaper ${} < @init < @load < @bind more expensive

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2017-12-18 16:50:32 +0800

Seen: 17 times

Last updated: Dec 22 '17