0

Can't get global command parameter if sent programmatically

asked 2018-07-20 17:10:15 +0800

aalfodel gravatar image aalfodel
1

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:


index.zul

<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>

IndexVM.java

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();
    }
}

child.zul

<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>

ChildVM.java

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");
    }
}
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-22 04:35:36 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...
 pipeHashMap.put("child-text", childText);

vs

@BindingParam("pipeHashMap") Map<String,Object>

it should be :

@BindingParam("child-text") String childText

Chill.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2018-07-20 17:10:15 +0800

Seen: 35 times

Last updated: Aug 30 '18

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More