-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have two zul files, each one linked to its own ViewModel. I'd like to programmatically pass some parameters from the "child" ViewModel to the "index" ViewModel, and to do so I'm using on the "child" ViewModel BindUtils.postGlobalCommand and a Map containing the values. The problem is, the global command on the "index" ViewModel gets called but the argument is not passed (pipeHashMap on getChildHashMap() results null). Here's my code:
<zk>
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('indexvm')@init('ZKTEST.ZKTEST_global_command_param_passing.IndexVM')"
validationMessages="@id('vmsgs')">
<include src="WEB-INF/child.zul"/>
<label value="@bind(indexvm.indexText)"/>
</window>
</zk>
package ZKTEST.ZKTEST_global_command_param_passing;
import java.util.Map;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;
public class IndexVM {
private String indexText;
public String getIndexText() {
if(indexText == null)
indexText = "initial value";
return indexText;
}
public void setIndexText(String indexText) {
this.indexText = indexText;
}
@GlobalCommand("indexGet")
@NotifyChange("indexText")
public void getChildHashMap(@BindingParam("pipeHashMap") Map<String,Object> pipeHashMap) {
System.out.println("EXECUTING GLOBAL COMMAND on index.vm");
System.out.println("pipeHashMap RECEIVED: " + pipeHashMap);
indexText = pipeHashMap.get("child-text").toString();
}
}
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('childvm')@init('ZKTEST.ZKTEST_global_command_param_passing.ChildVM')"
validationMessages="@id('vmsgs')">
<textbox value="@bind(childvm.childText)"/>
<button label="send" onClick="@command('send')"/>
</window>
package ZKTEST.ZKTEST_global_command_param_passing;
import java.util.HashMap;
import java.util.Map;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Command;
public class ChildVM {
private String childText;
public String getChildText() {
return childText;
}
public void setChildText(String childText) {
this.childText = childText;
}
@Command("send")
public void sendChildHashMap() {
Map<String,Object> pipeHashMap = new HashMap<String,Object>();
pipeHashMap.put("child-text", childText);
System.out.println("pipeHashMap TO SEND: " + pipeHashMap);
BindUtils.postGlobalCommand(null, null, "indexGet", pipeHashMap);
System.out.println("pipeHashMap SENT");
}
}
pipeHashMap.put("child-text", childText);
vs
@BindingParam("pipeHashMap") Map<String,Object>
it should be :
@BindingParam("child-text") String childText
Chill.
Asked: 2018-07-20 17:10:15 +0800
Seen: 35 times
Last updated: Aug 30 '18
[Smalltalk] Template Examples -Locker
Custom- Session TimeOut Message [closed]
No invisible modal window in class deriving Window [closed]
Update from ZK 8.0.2.2 to 8.5.0 (with ZK-Studio)
Popout ZK Tab to Browser [closed]
SCRIPT: Permission denied in IE11 and Edge
'Problems encountered while deleting resources' for Zk-Spring-Boot project