0

My advice is .zul can call any method in .java

asked 2011-11-15 05:51:02 +0800

volking gravatar image volking
3

updated 2011-11-15 05:54:35 +0800

My advice is .zul can call any method in .java

such as
<window title="Search Storage Item" border="normal" width="600px"
apply="org.zkoss.bind.BindComposer" viewModel="@bind(vm='org.zkoss.bind.examples.search.SearchVM')" >
...
<textbox value="@bind(vm.filter)" instant="true"></textbox>
<textbox value="@getFilter()" instant="true"></textbox> //call getFilter() method in SearchVM.java file

<listcell label="@bind(item.price) @converter('formatedNumber', format='###,##0.00')"></listcell>

Do not remember a lot of syntax
More simple
<listcell label="@getPrice(item.price) "></listcell> //call getPrice(doubel price) method

SearchVM.java
public String getPrice(double price){
return new DecimalFormat("###,##0.00").format(price);
}

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2011-11-18 01:29:44 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

updated 2011-11-18 01:31:19 +0800

ZK Bind utilize EL 2.2 expression syntax, so it accepts method calls the way EL 2.2 allowed. e.g.

Following should be already there in ZK Bind.

<textbox value="@bind(vm.getFilter())" instant="true"></textbox> //call getFilter() method in SearchVM.java file

The above will make binder evaluate (thru EL 2.2 evaluator engine) vm.getFilter() when the page is first loaded (loading). And it will try to do "save" to vm.getFilter() when the value of textbox is changed (saving) and EL engine will complain about no way to "save" (the syntax is not legal in EL 2.2). So saving is not going to work.

How about a loading only UI component? Say, label.

<label value="@bind(vm.getFilter())"></label> 

which will do the work since it only do loading. However, compare to "vm.filter" expression

<label value="@bind(vm.filter)"></label>

"vm.getFilter() " lost a hint to binder. The "vm.filter" tells binder that "filter" is a property of vm while "vm.getFilter()" tells binder that "getFilter()" is a method of vm. Thus binder cannot do "auto synchronizing" of the filter property for you if you use "vm.getFilter()" expression. That is, even system tells binder that "Hey, the filter property of vm has changed", binder doesn't know that it shall "synchronize" the new changed value into the label because it thoughts it is a method.

And this should be already there in ZK Bind.

<listcell label="@bind(vm.getPrice(item.price))"></listcell> //call getPrice(doubel price) method

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
3 followers

RSS

Stats

Asked: 2011-11-15 05:51:02 +0800

Seen: 770 times

Last updated: Nov 18 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More