Server-side Listeners"

From Documentation
m
m
Line 25: Line 25:
 
</source>
 
</source>
  
Notice that on the receipt of the <mp>ClearEvent</mp> we update the _cleared property at the server side. Imagine if this event is not sent then we have a problem as the client and server side will be out of sync. To get around this we can register the event as important.
+
Notice that on the receipt of the <mp>ClearEvent</mp> we update the <mp>_cleared</mp> property at the server side. Imagine if this event is not sent then we have a problem as the client and server side will be out of sync. To get around this we can register the event as important.

Revision as of 06:29, 14 July 2010

Then we move on and fire the "onClear" event. To fully understand what happens next we now need to investigate server side listeners which handle these events. A client event will not be sent to the server if it has not been registered. To give the developer the ability to register an event listener at the serverside we need to declare the events. We do this using the function addClientEvent.

The following example demonstrates declaring a clear event at the server.

static {
		addClientEvent(SimpleLabel.class, ClearEvent.NAME, 0);
	}

We have noted that if an event is not registered at the server side then it will not be sent from the client. However, in our example there is a problem if the event is not sent back. Let’s cast our mind back to the service method we implemented.

public void service(org.zkoss.zk.au.AuRequest request, boolean everError) {
		final String cmd = request.getCommand();

		if (cmd.equals(ClearEvent.NAME)) {
			ClearEvent evt = ClearEvent.getClearEvent(request);
			_cleared = evt.getCleared();
			Events.postEvent(evt);
		} else
			super.service(request, everError);
	}

Notice that on the receipt of the ClearEvent we update the _cleared property at the server side. Imagine if this event is not sent then we have a problem as the client and server side will be out of sync. To get around this we can register the event as important.