Search code examples
zk

Programmatically add composer while creating a component


I need to create a window component from a ZUML using different composers. But i cant figure out how to do this programmatically. It works fine when I apply the composer to the window within the ZUML file.

This works

dataTemplate.zul

<window id="dataTemplateWindow"
apply="dk.dataproces.cpraap.controllers.DataTemplateWindowController">
          ....

Controller

dataTemplateWindow = (Window) Executions.createComponents(
                "dataTemplate.zul", homeWindow, null);

I would like to do something like this

No composer is attached within the ZUML, and it is instead added programmatically.

Map data = new HashMap();
data.put("composer","dk.dataproces.cpraap.controllers.DataTemplateWindowController");
dataTemplateWindow = (Window) Executions.createComponents("dataTemplate.zul", homeWindow, data);

The reason is I need to attach different controllers to the same ZUML.


Solution

  • Your almost there.

    You just need to declare in the second zul that the composer comes from the arg map.

    You do this in the zul by :

    apply="${arg.composer}"
    

    Here is a test fiddle where I did it.