-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi everyone,
I'm currently writing a program using ZKoss MVVM pattern.
What I want to do is displaying live data received from a distant server. To do so I need to have it transferred through all the layers of my app automatically, so that when the server pushes data my end user's View gets updated.
Architecture :
View <--> ViewModel <--> Model <--> Server
Where it gets tricky :
ViewModel <-- Model
I don't know the best pratice to get my ViewModel's properties updated once my Model has been updated.
I've though about implmenting the Observable/Observer pattern. The Model would be observed by the ViewModel and it would then get its properties updated automatically. I wanted to know if there's a better way to bind Models to ViewModels.
Hello valnay
A good example of how to accomplish your task is the following:
a. zul grid
<grid id="sampleGird" model="@load(vm.sampleModel)"
<auxhead>
<auxheader label="Sample Grid" colspan="1">
</auxheader>
</auxhead>
<columns>
<column label="Users" width="100%"/>
</columns>
<rows>
<template name="model" var="item">
<row>
<cell style="text-align: left;">
<label value="@load(user.name)"/>
</cell>
</row>
</template>
</rows>
</grid>
b. java class
In the java class you have to declare the following:
@Wire("#sampleGird")
private Grid sampleGird;
private ListModelList<User> sampleModel;
And you will use a method to update the model and the grid as shown bellow:
@GlobalCommand
@NotifyChange({"sampleModel", "sampleGird"})
public void populateGrid() {
sampleModel = new ListModelList<>();
User user = new User();
user.setName("Sample User");
List<User> userList = new ArrayList<User>();
userList.add(user);
sampleModel.addAll(userList);
}
If you need more help, i can provide you with a full working example.
Best Regards,
Darksu
Asked: 2014-07-02 09:56:46 +0800
Seen: 34 times
Last updated: Jul 25 '14
Editable interface to add users
Problem binding values to a composite component
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
[Ugent please] connect Web service .net view in grid group ZK
Dirty state for forms with collection properties