0

How to execute block of code inside doaftercompose

asked 2020-07-27 23:43:20 +0800

codeLearner gravatar image codeLearner
1

In my current project, multiple .zul file applies a composer. In that composer, I have called multiple functions each of which is related to those .zul files. An example of the code is given below:

// variable for first .zul
@Wire               
Combobox cb_1;

// variable for second .zul
@Wire               
Combobox cb_2;

// variable for third .zul
@Wire               
Combobox cb_3;

public void doAfterCompose(Component comp) throws Exception{
    super.doAfterCompose(comp);

    function_1();          // for first .zul file
    function_2();          // for second .zul file
    function_3();          // for third .zul file
}

These functions inside doAfterCompose() populate Combox in those .zul file dynamically. The problem is, say, if I run first .zul file and call only function1() then the program works. Same for other .zul files and functions. But if I run any .zul file but call all of the functions then NullPointerException occurs for the ComboBox variables which are part of other .zul files. I want the code to work like this: all of the functions will be mentioned in the doAfterCompose section but only the necessary one will be called. Say, for first .zul file function1(), for second .zul file function_2(). How to do this? Or if there is any other option.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-28 10:29:31 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

Hi codeLearner,

You pointed out the main problem already: you are using a single Composer for multiple different files. This will not make anything easier.

A better approach is to make a GenericComposer (which contain all of the shared methods and properties) and extend it for each zul file.

You would have a

class GenericComposer extends SelectorComposer{
     // generic code shared by all of your individual page composers here

}

then you can make new classes such as:

Page1Composer extends GenericComposer{
@Wire               
Combobox cb_1;

    public void doAfterCompose(Component comp) throws Exception{
        super.doAfterCompose(comp);
        function_1();          // for first .zul file
    }
}

Page2Composer extends GenericComposer{
@Wire               
Combobox cb_2;

    public void doAfterCompose(Component comp) throws Exception{
        super.doAfterCompose(comp);
        function_2();          // for second .zul file
    }
}

etc.

Basically, if it's a shared process or variable, put it in the generic "super" composer. If it's a page-related thing, put it in the page-specific composer.

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

RSS

Stats

Asked: 2020-07-27 23:43:20 +0800

Seen: 11 times

Last updated: Jul 28 '20

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