RAP ClientServices explainedDecember 17, 2012 | 3 min Read
One of the bigger changes in the RAP 2.0 API is the introduction of client services. These are features that interact with the client, but aren’t directly related to the widget toolkit. Since there are now multiple types of clients that can be connected (mainly our default WebClient, Tabris for iOS and Tabris for Android), as well as different environments (browser, OS version, hardware), not all of these features may be available at all times.
The client service API accounts for that. In RAP 2.0, the client is represented by a class implementing the
Client interface (
WebClient by default). An instance of this class can be obtained from
RWT.getClient(), which selects an implementation that matches the currently connected client. This implementation then provides the client services via the
getService method. For example:
MyService service = RWT.getClient().getService( MyService.class );
If the client connected to the current session supports the service, an instance is returned, otherwise null. (Also, within one session it will always return the same instance for the same service.) If you can be certain that the service is supported by all clients you are targeting, you can use it immediately, otherwise you should check for null first.
Right now, all services that are part of RAP are supported by the WebClient at all times. Some of them provide features that already existed in RAP 1.x in some form, some of them are completely new. There will certainly be even more in the future, especially ones that are based on HTML5-only features. As such, their availability at runtime may depend on the currently connected browser.
For now there is:
- ClientInfo: Provides you with the clients timezone offset and locale setting.
- BrowserNavigation: Allows you to support the browser’s back/forward button and deep linking.
- ExitConfirmation: Lets you set a message that is displayed if the users tries to close the window or navigate to another website.
- UrlLauncher: Open any given URL without leaving the application or influencing the client. May be used to open other websites, view files, start mailing or calling a specific person. May also support opening save dialogs in the future.
Update: You can try all services in the updated Controls Demo.