Server-side Processing

From Documentation


Server-side Processing



Process AU Requests at Server

ClientEventAuRequest.gif

A widget event (Event) is converted to an AU request and then sent to the server. When the event arrives at the server, it is converted to be an instance of AuRequest), and then pass to the desktop for serving by invoking DesktopCtrl.service(AuRequest, boolean). If the request is targeting a component, the component's ComponentCtrl.service(AuRequest, boolean) will then be called to serve it.

Component State Synchronization

Thus, if you implement a component, you could override ComponentCtrl.service(AuRequest, boolean) to handle it.

Here is an example (from Radio):

public void service(org.zkoss.zk.au.AuRequest request, boolean everError) {
	final String cmd = request.getCommand();
	if (cmd.equals(Events.ON_CHECK)) {
		CheckEvent evt = CheckEvent.getCheckEvent(request);
		_checked = evt.isChecked();
		fixSiblings(_checked, true);
		Events.postEvent(evt);
	} else
		super.service(request, everError);
}

Application-level Notification

If the AU request is sent by an application for custom service, you could implement AuService to serve it and then plug it to the targeted component or desktop, depending on your requirement. If the request is targeting a desktop, you can only intercept it at the desktop-level. If targeting a component, you could intercept it at either component-level or desktop-level.

Since all requests will be passed through AuService that you plug, the performance of the implementation shall be good. In additions, this method shall return true if it has been processed to avoid any further processing.

public class FooAuService implements AuService {
    public boolean service(AuRequest request, boolean everError) {
        final String cmd = request.getCommand();
        if ("onFoo".equals(cmd)) { //assume onFoo a custom request
            //handle it
            return true; //indicate it has been processed
        }
        return false; //not processed at all
    }
}

Intercept at Desktop-level

To plug it to the desktop, you could implement a listener of DesktopInit to add it to a desktop by Desktop.addListener(Object). Then, specify the listener to WEB-INF/zk.xml. For example,

package foo;
public class FooDesktopInit implements DesktopInit {
    public void init(Desktop desktop,  Object request) throws Exception {
        desktop.addListener(new FooAuService()); //assume you have a custom service called FooAuService
    }
}

and, in WEB-INF/zk.xml

<listener>
	<listener-class>foo.FooDesktopInit</listener-class>
</listener>

Intercept at Component-level

To plug it to the component, you could invoke Component.setAuService(AuService).

Client Event Declaration

Important Events

Version History

Last Update : 2010/12/20


Version Date Content
     



Last Update : 2010/12/20

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.