Serialization Listeners

The attributes, variables, and listeners stored in a component, a page, a desktop or a session are also serialized if they are serializable (and the corresponding component, page, desktop or session is serialized).

To simplify the implementation of serializable objects, ZK invokes the serialization listener before serialization and after de-serialization, if the special interface is implemented. For example, you can implement an event listener for a component as follows.

public MyListener
implements EventListener, java.io.Serializable, ComponentSerializationListener {
    private transient Component _target; //no need to serialize it    

    //ComponentSerializationListener//    
    public willSerialize(Component comp) {    
    }    
    public didDeserialize(Component comp) {    
        _target = comp; //restore it back        
    }    
}

The org.zkoss.zk.ui.util.ComponentSerializationListener interface is used when serializing a component. Similarly, PageSerializationListener, DesktopSerializationListener and SessionSerializationListener are used when serializing a page, desktop and session, respectively.