-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all, I'm very sorry for the question, but even if I looked a lot in the forum and online I can't find a solution to this simple questio:
I'm using org.zkoss.bind.BindComposer for binding and I want to update a doublebox value when an element from a listbox is selected.
I binded correctly the listbox and tried to alterate the values binded to the doublebox by acting on the getters and setters of the selecteditem, but even if the values changes on the debugger they are not updated on the view;
the zul code is the following:
<listbox model="@id('opts') @bind(domanda.sectorOptions)" selectedItem="@bind(domanda.selectedItem)" onSelect="@command('countValues')" emptyMessage="Daabase connection error, please contact the MIPEL Secretariat"> <listhead> <listheader width="560px" label="Opzione" ></listheader> <listheader width="200px" label="Costo al metro quadro" ></listheader> <listheader width="200px" label="metratura minima consentita" ></listheader> </listhead> <template name="model" var="opt"> <listitem> <listcell label="@load(opt.labelIt)" ></listcell> <listcell label="@load(opt.cost)" ></listcell> <listcell label="@load(opt.minArea)" ></listcell> </listitem> </template> </listbox> <hbox> <label width="135px" value="Metri quadrati" ></label> <doublebox id="sm" value="@bind(domanda.squareMeters)" ></doublebox> </hbox>
Yes, you're right.
But in ZUL
maybe value="@bind(vm.example.value)" in doublebox tag is redundant.
If you want to use @bind approch
use a variable in your ViewModel and @Notifychange("variable") on the @command method
There're many ways to implement same thing, so choose the way you like.
http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/MVVM/Syntax/ViewModel/@NotifyChange
so... to be sure cause it's not working the way I'm doing it:
Java
... @Wire private Doublebox example; ... @AfterCompose public void afterCompose(@ContextParam(ContextType.VIEW) Component view) { Selectors.wireComponents(view, this, false); } ... public void letsTest(){ ... example.setValue("Hello world"); ... } ...
Zul
... <doublebox id="example" value="@bind(vm.example.value)">
is it right?
Hello, jbiscella
1. use @Wire annotation on "Doublebox" in your ViewModel.
2. use Selectors.wireComponents(view, this, false); in your @aftercompose phase. (If you're using version before 6.5, use @Init instead.)
@bind in ZUL will auto update the value, just like you saw in debugger. Just wire your component with ViewModel, UI will update automatically.
Hi,
Did you remember wire component in viewmodel?
http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/MVVM/Advance/Wire%20Components
Asked: 2013-01-14 16:26:13 +0800
Seen: 67 times
Last updated: Jan 15 '13