The onClientInfo Event

Sometimes an application needs to know the client's information, such as time zone. Then, you can add an event listener for the onClientInfo event. Once the event is added, the client will send back an instance of the org.zkoss.zk.ui.event.ClientInfoEvent class, from which you can retrieve the information of the client.

<grid onClientInfo="onClientInfo(event)">
    <rows>    
        <row>Time Zone <label id="tm"/></row>        
        <row>Screen <label id="scrn"/></row>        
    </rows>    
                
    <zscript>    
    void onClientInfo(ClientInfoEvent evt) {    
        tm.setValue(evt.getTimeZone().toString());        
        scrn.setValue(        
            evt.getScreenWidth()+"x"+evt.getScreenHeight()+"x"+evt.getColorDepth());            
    }    
    </zscript>    
</grid>

Note: The onClientInfo event is meaningful only to the root component (aka., a component without any parent).

The client information is not stored by ZK, so you have to store it manually if necessary. Since a session is associated with the same client, you can store the client info in the session's attribute.

session.setAttribute("px_preferred_time_zone", event.getTimeZone());

Notice that, if you store a time zone as a session variable called px_preferred_time_zone, then its value will be used as the default time zone thereafter. Refer to the Time Zone section in the Internationalization chapter.

Notice that the onClientInfo event is sent from the client after the page is rendered (and sent to the client). Thus, if some of your component's data depends on the client's info, say, time zone, you might have to ask the client to re-send the request as follows.

import org.zkoss.util.TimeZones;
...
if (!TimeZones.getCurrent().equals(event.getTimeZone())
    Executions.sendRedirect(null);