Strange behaviour of composite component and menupopup

asked 2016-01-23 13:10:42 +0800

Bhushanngage gravatar image Bhushanngage
59 6

I have one composite component. Its zul is cc.zul

<div context="editPopup">
    <label id="lbl" />
<menupopup id="editPopup">
    <menuitem label="Message" />
    <menuitem label="Profile" />

Its corresponding listener is CompositeComp.java

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.MouseEvent;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Div;
import org.zkoss.zul.Label;
import org.zkoss.zul.Messagebox;

public class CompositeComp extends Div implements IdSpace {

Label lbl;

// Default Constructor.
public CompositeComp(int id) {
    Executions.createComponents("cc.zul", this, null);
    Selectors.wireComponents(this, this, false);
    Selectors.wireEventListeners(this, this);
    this.id = id;
    lbl.setValue("Hello " + id);

public int getCompId() {
    return id;
    //Here is magic happening
@Listen("onClick = menuitem")
public void onSelectMenu(MouseEvent event) {

I want to show above composite component in my container.zul

<window id="win" apply="the.bhushan.zk.listeners.Container">
    <div id="container" />

Listener Container.java is as follow

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Div;

public class Container extends SelectorComposer<Component> {

    Div container;

    public void doAfterCompose(Component comp) throws Exception {
        for (int i = 0; i < 5; i++) {
            container.appendChild(new CompositeComp(i));

In listener Container.java, I am appending Composite component 5 times. When I right click on any component in screen, and after clicking any menu Messagebox shows value "4" always. Please help.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-24 20:03:27 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9

If you check on what class is triggered, you will find out that it's always the same menupopup what's behind it.

Here is a fiddle what resolves your issue. I'm just giving a unique id to the menupopup so the reference can be set correct.


link publish delete flag offensive edit


@chillworld - Great, it worked.

Bhushanngage ( 2016-01-27 05:03:52 +0800 )edit

@chillworld - Though, it worked, I still didn't get what was the issue :(

Bhushanngage ( 2016-01-28 06:03:34 +0800 )edit

mine guess is that the menupopup ID is going through the IdSpace witch resolves in taking the last one created for all popups.

chillworld ( 2016-01-28 06:25:30 +0800 )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: 2016-01-23 13:10:42 +0800

Seen: 17 times

Last updated: Jan 24 '16

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