-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a MVVM grid where I am displaying a list of currency exchange rates. The grid has the following columns:
The user can choose to enter a new exchange rate in any cell under the 'Exchange Rate' column' or choose to change the 'Multiply/Divide' radio button selection. In either case I would like the values under the 'Example result' column cell to be updated immediately.
How can I do this under MVVM? Is it possible to define '@DependsOn' annotations at a grid or listbox row level?
An easier way is calculate value in zul page via mvvm,
e.g.,
zul
<zk>
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('test.TestVM')">
<grid model="@bind(vm.model)">
<template name="model">
<row>
<intbox value="@bind(each.cost)"/>
<intbox value="@bind(each.amount)"/>
<label value="@bind(each.cost * each.amount)"/>
</row>
</template>
</grid>
</window>
</zk>
TestVM.java
package test;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
/**
* tested with ZK 6.5.1.1
*
* @author benbai
*
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class TestVM {
ListModelList _model;
public ListModel getModel () {
if (_model == null) {
List l = new ArrayList();
Random r = new Random();
for (int i = 0; i < 10; i++) {
l.add(new TestData(r.nextInt(10), r.nextInt(10)));
}
_model = new ListModelList(l);
}
return _model;
}
}
TestData.java
package test;
public class TestData {
private int _cost;
private int _amount;
public TestData (int cost, int amount) {
_cost = cost;
_amount = amount;
}
public void setCost (int cost) {
_cost = cost;
}
public int getCost () {
return _cost;
}
public void setAmount (int amount) {
_amount = amount;
}
public int getAmount () {
return _amount;
}
public int getTotalPrice () {
return _cost * _amount;
}
}
or you need to handle event and notify change manually.
Thanks for the suggestion...
I'd managed to work out a solution that uses 'onChange' type events on the input fields to call a '@command('updateCalcs') MVVM method that does the dependent field calculations, and then on the dependent fields use a '@load(vm.example,after='updateCalcs') annotation that will update accordingly.
This does seem a little ponderous. I'm wondering why ZK doesn't provide @DependsOn support at a model row level.
Asked: 2013-05-15 07:54:01 +0800
Seen: 21 times
Last updated: May 20 '13
Databinding and auto-complete on combobox
Composite component and bind in ZK 6
How to detach / reattach MVVM windows?
Is there a way to resolve view model properties as input to client side javascripts?
How can I synchronize data in a ListBox in MVVM ? [closed]
MVVM Validator: class not found ? [closed]
How to Call Child ViewModel Method from Parent Window? [closed]