-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a ZUL page which included some other pages inside it and in my parent ZUL i have this scenario.
<window title="new page title" border="normal" id="inp"
viewModel="@id('vm') @init('com.team.MyListbox')" apply="org.zkoss.bind.BindComposer" ctrlKeys="^a^s^d#f8" onCtrlKey="@command('ctrlKeyClick',item=event.getKeyCode())">
Now you can check i am calling a method ctrlKeyClick in parent viewmodel but somehow it is possible whenever user will use CTRL KEY I can pass keyCode in my Child View Method OR Can i call Child class method from inside Parent View Model. As we did in when we will want parent method from child viewmodel..
Binder bind = (Binder) view.getParent().getAttribute("binder");
if (bind == null)
return;
bind.postCommand("doSomething", params);
Can we do something like his in my my case?
For this i used a different Approach . .i got another idea and look like it is working fine with me What i did? I made a Singleton Class and added a variable of Component class with get/set method. Now in each of my view Model afterCompose() i am calling setter method of Component variable from singleton class, and passing current viewModel Component object to it and in my HomeViewModel CTRL key event method i adding this code so it calling method from Selected tab .
Component ctrlkeyComp = idBinder.getCompObject();
if(ctrlkeyComp != null){
Binder bind = (Binder) ctrlkeyComp.getAttribute("binder");
if (bind == null)
return;
bind.postCommand("doActionInChildVM", map);
}
use Global Command and BindUtils to listen to and post command between view model
For example,
ZUL
<window>
<hlayout>
<vlayout apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('simple.ViewModel1')">
<button label="post1" onClick="@command('post1')"/>
<textbox value="@bind(vm.value)"/>
<label value="@bind(vm.value)"/>
</vlayout>
<vlayout apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('simple.ViewModel2')">
<button label="post2" onClick="@command('post2')"/>
<textbox value="@bind(vm.value)"/>
<label value="@bind(vm.value)"/>
</vlayout>
</hlayout>
</window>
ViewModel 1
package simple;
import java.util.HashMap;
import java.util.Map;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;
public class ViewModel1 {
String value = "model1";
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Command
public void post1(){
Map arg = new HashMap();
arg.put("value", this.value);
BindUtils.postGlobalCommand(null, null, "globalpost1", arg);
}
@GlobalCommand @NotifyChange("value")
public void globalpost2(@BindingParam("value") String value){
this.value = value;
}
}
ViewModel 2
package simple;
import java.util.HashMap;
import java.util.Map;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;
public class ViewModel2 {
String value = "model2";
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Command
public void post2(){
Map arg = new HashMap();
arg.put("value", this.value);
BindUtils.postGlobalCommand(null, null, "globalpost2", arg);
}
@GlobalCommand @NotifyChange("value")
public void globalpost1(@BindingParam("value") String value){
this.value = value;
}
}
Asked: 2013-02-04 10:13:49 +0800
Seen: 188 times
Last updated: Feb 19 '13
Why does the order of NotifyChange may alter the result of the objects?
Is there a way to resolve view model properties as input to client side javascripts?
zk mvvm focus textbox after a button clicked
ZK MVVM Listbox Mold Paging - select first record on each page [closed]
zul.mesh.wpd this.$n().style is null
Redirect modal window without changing parent window. [closed]