-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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);
}
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
Asked: 2011-11-15 05:51:02 +0800
Seen: 770 times
Last updated: Nov 18 '11