passing object from zul to controller

asked 2014-01-29 18:13:09 +0800

robertkaren gravatar image robertkaren
77 7

I am new to zk and am having trouble with this. I have a textbox for a filename with a 'browse' button next to it which will open another window (below).I am having trouble passing the textbox (object or path) to the controller of the new window. I want it to set value of the original textbox after user selects something from tree in popup window. What is best way to pass it to the 2nd window's controller. I don't want to hardcode a path to the textbox because I want to reuse the popup's controller elsewhere. Thanks for any help!

Button creating new window:

    public class SaveFileTabpanelController extends SelectorComposer<Component> {
    private Window window;
    Textbox filenameTextbox;
    @Listen ("onClick = #browseBtn")
    public void onClickBrowseBtn() {
        String template = "browseFolder.zul"
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("testString", "test string 1");
        args.put("textbox", filenameTextbox);
        window = (Window)Executions.createComponents(template, null, args);

new window zul:

    <window id="browseFolderOuterWin" title="Select a folder" 
height="500px" width="400px" 
        <north>     <label id="testLbl" value="123"/>
        <center border="0">
                <tree id="foldersTree" style="height:18px;"
                       width="100%" vflex="true">
                    <treecols sizable="true">
                        <treecol width="100%"/>
                    <treecell label="${arg.testString}" >
                       <attribute name="onDoubleClick">
                        testLbl.setValue(self.getLabel() + "rk");
                    <treecell label="dir 2"/>
        <south border="0">
            <hbox width="100%" pack="center">
                <button id="closeBtn" label="Close" />

controller of new window:

    public class BrowseFolderController extends SelectorComposer<Component> {
        private Window window;
        String testString2 = null;
        Window browseFolderOuterWin;
        @Listen ("onClick = #closeBtn")
        public void onClickCloseBtn() {
            System.out.println(this + " detaching, testString2 = " + testString2);
delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-02-02 02:26:21 +0800

robertkaren gravatar image robertkaren
77 7

Thanks! That worked. It took awhile before I figured out I needed to extend GenericForwardComposer. Thanks again.

link publish delete flag offensive edit


Ofcourse we have to extend GenericForwardComposer in Controller to use the objects from zul.

MVarun ( 2014-02-03 07:54:28 +0800 )edit

you can use selectorcomposer to, but you will add annotations.

chillworld ( 2014-02-03 08:25:44 +0800 )edit

Can you tell me what annotation to add to let me read the 'arg' parameters I am reading in doAfterCompose (below)? I was trying to do that. Thanks.

robertkaren ( 2014-02-03 15:18:44 +0800 )edit

If you extended the genericcomposer you dont need annotations. Just reader the args in doaftercompose and save it to some variablen. If you want to use selectorcomposer. Search the docs for more info.

chillworld ( 2014-02-03 16:05:40 +0800 )edit

I am using SelectorComposer, I searched documents but still not getting how to access arg in SelectorComposer.

Bhushanngage ( 2015-09-29 05:32:09 +0800 )edit

answered 2014-01-29 20:57:37 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9

For the quick view I took, you where good on the way. If your problem is that testString2 is still null that is because you have to override the doAfterCompose like this :

public void doAfterCompose(Component window) throws Exception {
    if (arg.containsKey("testString")) {
        testString2 =  (String) arg.get("testString"));

If you want the template string a little more flexibler you could use propertie file for that.

Greetz 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

1 follower



Asked: 2014-01-29 18:13:09 +0800

Seen: 54 times

Last updated: Feb 02 '14

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