Search code examples
javazk

Zk how to pass parameter from java code to zk page?


I am novice in ZK.

I use very old zk framework version(legacy project).

I render zk page so:

Executions.createComponents("/myZul.zul", null, null))

I need to pass parameter to zul. And if parameter is true I need render checkbox and otherwise - not on myZul.zul

I need something like this on zul:

if(parameter){

    <checkbox id="my_id" label="my checkbox"  />
}

UPDATE my zul:

<window xmlns="http://www.zkoss.org/2005/zul" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:h="http://www.w3.org/1999/xhtml" 
        xmlns:zk="http://www.zkoss.org/2005/zk"
        xmlns:ca="http://www.zkoss.org/2005/zk/client"
        xsi:schemaLocation="http://www.zkoss.org/2005/zul      http://www.zkoss.org/2005/zul/zul.xsd "
        border="normal"
        closable="false"
        position="center,center"
        width="383px"
        height="270px"
        onCancel="self.detach();"
        id="decisionCommentWindow"
        title="${c:l('approvalTaskWindow.title')}"
        use="handlers.ZulHandler">
        ....

I need override method doAfterCompose inside of ZulHandler?

One more time:

zul:

<window xmlns="http://www.zkoss.org/2005/zul" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:h="http://www.w3.org/1999/xhtml" 
        xmlns:zk="http://www.zkoss.org/2005/zk"
        xmlns:ca="http://www.zkoss.org/2005/zk/client"
        xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd "
        border="normal"
        closable="false"
        position="center,center"
        width="383px"
        height="270px"
        onCancel="self.detach();"
        id="decisionCommentWindow"
        title="${c:l('approvalTaskWindow.title')}"
        use="handlers.ZulHandler">


    <zk if="${isManufacturingKey}">

        <checkbox id="checkbox_id" label="check"  />

    </zk>






</window>

zul creater:

...
Map args = new HashMap<String, Boolean>();
                    Boolean isManufacturing = true;
                    args.put("isManufacturingKey", isManufacturing);
                    ZulHandler window = Preconditions
                            .checkNotNull((ZulHandler) Executions.createComponents(
                                    "/decision_comment_window.zul", null, args));
                    window.setTitle(decisionModel.getName() + " decision");
                    if (isManufacturing) {
                        Checkbox checkbox = (Checkbox) Path
                                .getComponent("/decisionCommentWindow/emergency_change_checkbox_id");
                        checkbox.setChecked(workflow.getEmergencyChange());//I have Null pointer here  because checkbox is null
                    }
...

Solution

  • java code:

    Map args = new HashMap<String, Boolean>();
    args.put("isManufacturingKey", true);
    ZulHandler window = Preconditions.checkNotNull((ZulHandler) Executions.createComponents("/decision_comment_window.zul", null, args)); 
    

    right access in .zul file:

    "${arg.isManufacturingKey}"
    

    note: I access to parameter using arg accessor

    It is working for my ZK version!!!