The onOpen Event

When a context menu, a tooltip or a popup is going to appear (or hide), an onOpen event is sent to the context, tooltip or poup menu for notification. The event is an instance of the org.zkoss.zk.ui.event.OpenEvent class, and you can retrieve the component that causes the context menu, tooltip or popup to appear by calling the getReference method.

To improve the performance, you defer the creation of the content until it becomes visible – i.e., until the onOpen event is received.

The simplest way to defer the creation of the content is to use the fulfill attribute as shown below.

<popup id="any" width="300px" fulfill="onOpen">
<button label="Hi"/><!-- whatever content -->
</popup>

Then, the content (the Hi button) won't be created when the page is loaded. Rather, the content is created when the onOpen event is received at the first time.

If you prefer to dynamically manipulate the content in Java, you can listen to the onOpen event as depicted below.

<popup id="any" width="300px">
    <attribute name="onOpen">    
    if (event.isOpen()) {    
        if (self.getChildren().isEmpty()) {        
            new Button("Hi").seParent(self);            
            ...            
        }        
        if (event.getReference() instanceof Textbox) {        
            //you can do component-dependent manipulation here            
            ...            
        }        
    }    
    </attribute></popup>