In RAP, the sessoin store is the preferred way to store information in the session context. However it also provides access to the HTTP session (see the code below). For working with session singletons, please use the <code>SessionSingletonBase</code> class.

In RAP, the sessoin store is the preferred way to store information in the session context. However it also provides access to the HTTP session (see the code below). For working with session singletons, please use the <code>SessionSingletonBase</code> class.

=== How to integrate the Eclipse Help System in a RAP application? ===

=== How to integrate the Eclipse Help System in a RAP application? ===

Line 251:

Line 284:

=== What is a Session Singleton and how can I implement one? ===

=== What is a Session Singleton and how can I implement one? ===

−

A "session singleton" is an RWT-specific singleton, which provides access to a unique instance with session scope. This means that in the context of one user session <code>getInstance(Class)</code> will always return the same object, but for different user sessions the returned instances will be different. To archive it's "magic", session singletons should call SessionSingletonBase#getInstance(), which takes care of the proper scoping of the singleton instances. The following code snippet illustrates this pattern:

+

A "session singleton" is an RWT-specific singleton, which provides access to a unique instance with session scope. This means that in the context of one user session <code>getInstance()</code> will always return the same object, but for different user sessions the returned instances will be different. RWT provides a utility to easily create session singletons, called ''SingletonUtil''. Here's an example of a session singleton:

Accessing session singletons is possible only from threads which are associated with a session. The <code>UIThread</code> always has a such an association, therefore any code running in this thread can freely access session singletons. Any non-UI (i.e. "background") thread, trying to access session singletons, will fail and a <code>java.lang.IllegalStateException</code> will be thrown. The solution is to temporarily associate the thread with a session. Use <code>UICallBack#runNonUIThreadWithFakeContext</code>, to fakes a "request context" that allows the runnable code to access those singletons.

+

Note that session singletons can only be directly accessed from the UIThread or with a ''fake context''.

−

The following code snippet throws an exception because the <code>Runnable</code> is executed in a background thread, with no access to the session singleton.

+

More on session scope and session singletons can be found in the [http://eclipse.org/rap/developers-guide/devguide.php?topic=singletons.html&version=2.0 section on scopes and data stores in RWT] in the RAP Developer's Guide.

Since you have a multi user environment in RAP (=&gt; multiple Sessions at a time) but only one application wide equinox instance running which is shared between those sessions (application scope) things getting a little bit more complicated. Each session has its own workbench instance since the state of the UIs differ between sessions. So in principle you can easily access the core from the UI, but the other way round isn't possible without additional code.

Since you have a multi user environment in RAP (=&gt; multiple Sessions at a time) but only one application wide equinox instance running which is shared between those sessions (application scope) things getting a little bit more complicated. Each session has its own workbench instance since the state of the UIs differ between sessions. So in principle you can easily access the core from the UI, but the other way round isn't possible without additional code.

−

So what's happening in your code is that you try to access your GUI layer (session scope) from the bundle activator (application scope), which isn't possible as was just explained. Most of the time it is easy to move the code from the activator to the <code>IEntryPoint#createUI</code> or <code>IStartup#earlyStartup</code>. Both methods are executed in session scope context, so there won't be any <code>IllegalStateExceptions</code> thrown.

+

So what's happening in your code is that you try to access your GUI layer (session scope) from the bundle activator (application scope), which isn't possible as was just explained. Most of the time it is easy to move the code from the activator to the <code>EntryPoint#createUI</code> or <code>IStartup#earlyStartup</code>. Both methods are executed in session scope context, so there won't be any <code>IllegalStateExceptions</code> thrown.

=== How to add a link to an external URL? ===

=== How to add a link to an external URL? ===

Line 387:

Line 392:

* a download link (see above)

* a download link (see above)

−

* a service handler (implementation of <code>IServiceHandler</code>) to prvide the download content

+

* a service handler (implementation of <code>ServiceHandler</code>) to provide the download content

Below is an example of a very basic downloads service handler. The request has a parameter "filename" which indicates which content (either static or dynamically generated) should be sent to the client. The ''MyDataStore'' will known how to find the required content. In our example the content is retrieved as <code>byte[]</code> but <code>InputStream</code>s and <code>Reader</code>s can be easily accommodated as well.

Below is an example of a very basic downloads service handler. The request has a parameter "filename" which indicates which content (either static or dynamically generated) should be sent to the client. The ''MyDataStore'' will known how to find the required content. In our example the content is retrieved as <code>byte[]</code> but <code>InputStream</code>s and <code>Reader</code>s can be easily accommodated as well.

Use <code>java.awt.Graphics2D</code> as a canvas on which to draw the image. The server, where the application will be deployed, most probably has no graphics UI system installed. Therefore we need to run AWT in "headless mode" by setting the system property <code>java.awt.headless</code> to <code>true</code>.

Use <code>java.awt.Graphics2D</code> as a canvas on which to draw the image. The server, where the application will be deployed, most probably has no graphics UI system installed. Therefore we need to run AWT in "headless mode" by setting the system property <code>java.awt.headless</code> to <code>true</code>.

−

In the example below, the produced <code>BufferedImage</code> is placed in the <code>SessionStore</code> and the ''key'' is used to generate the new <code>&lt;img&gt;</code> tag for the <code>Browser</code>.

+

In the example below, the produced <code>BufferedImage</code> is placed in the <code>UISession</code> and the ''key'' is used to generate the new <code>&lt;img&gt;</code> tag for the <code>Browser</code>.

The service handler has to be registered with <code>RWT.getServiceManager().registerServiceHandler()</code> - see the first code snippet above. The handler receives the image ''key'' as a request parameter, and uses it to retrieve the image from the <code>SessionStore</code>.

+

The service handler has to be registered with <code>RWT.getServiceManager().registerServiceHandler()</code> - see the first code snippet above. The handler receives the image ''key'' as a request parameter, and uses it to retrieve the image from the <code>UISession</code>.

=== How to access a RAP application without specifying a servlet name? ===

=== How to access a RAP application without specifying a servlet name? ===

−

Let's suppose that we want to simplify the URL of our RAP application and be able to access it with <code><nowiki>http://www.example.org/webapp</nowiki></code> instead of <code><nowiki>http://www.example.org/webapp/servlet_name</nowiki></code>.

+

Let's suppose that we want to simplify the URL of our RAP application and be able to access it with <code><nowiki>http://www.example.org/webapp</nowiki></code> instead of <code><nowiki>http://www.example.org/webapp/servlet_path</nowiki></code>.

The recommended solution is to use a redirection servlet:

The recommended solution is to use a redirection servlet:

−

*Write a servlet which redirects requests for the web application root to the servlet name defined in the <code>org.eclipse.rap.branding</code> extension:

+

*Write a servlet which redirects requests for the web application root to your application servlet path:

'''Note:''' Since RAP 2.0 <code>UICallBack</code> has been replaced with <code>ServerPushSession</code>. Use <code>ServerPushSession#start()</code> and <code>ServerPushSession#stop()</code> to activate/deactivate it.

To allow automatic UI-updates by server side background threads the ''UI Callback'' needs to be activated. Call <code>UICallBack#activate</code> before the start of a thread and <code>UICallBack#deactivate</code> at the end. Each activation needs a session unique identifier as a kind of reference pointer to be able to decide when all background threads are finished.

To allow automatic UI-updates by server side background threads the ''UI Callback'' needs to be activated. Call <code>UICallBack#activate</code> before the start of a thread and <code>UICallBack#deactivate</code> at the end. Each activation needs a session unique identifier as a kind of reference pointer to be able to decide when all background threads are finished.

Line 849:

Line 844:

</source>

</source>

−

An alternative way is to register a <code>SessionStoreListener</code>:

RWT.getSessionStore().getHttpSession().setMaxInactiveInterval(<timeout in Seconds>);

+

RWT.getUISession().getHttpSession().setMaxInactiveInterval(<timeout in Seconds>);

</source>

</source>

Line 947:

Line 942:

=== How to run a RAP application in multiple browser tabs/windows? ===

=== How to run a RAP application in multiple browser tabs/windows? ===

+

+

Since RAP 2.1, multiple browser tabs are supported without any modifications (see {{bug|390236}} for details).

+

The following discussion is still valid for RAP versions prior to 2.1.

By default, servlet engines use [http://en.wikipedia.org/wiki/HTTP_cookie#Session_management|session cookies] to identify a session. Browsers usually re-use the same session cookie for all tabs and windows within the same process. In the end, the RAP servlet cannot distinguish request that come from the same browser/client-session and rejects request that come from a second tab or window with the message "Multiple browser-instances or browser-tabs per session are not supported. You may click OK for restarting the session.". For a complete history of this issue, please see {{bug|285398}}.

By default, servlet engines use [http://en.wikipedia.org/wiki/HTTP_cookie#Session_management|session cookies] to identify a session. Browsers usually re-use the same session cookie for all tabs and windows within the same process. In the end, the RAP servlet cannot distinguish request that come from the same browser/client-session and rejects request that come from a second tab or window with the message "Multiple browser-instances or browser-tabs per session are not supported. You may click OK for restarting the session.". For a complete history of this issue, please see {{bug|285398}}.

Line 971:

Line 969:

For the customizer to be picked up when Jetty is started, the following system property must be specified: <code>-Dorg.eclipse.equinox.http.jetty.customizer.class=org.eclipse.rap.jettycustomizer.internal.SessionCookieCustomizer</code>

For the customizer to be picked up when Jetty is started, the following system property must be specified: <code>-Dorg.eclipse.equinox.http.jetty.customizer.class=org.eclipse.rap.jettycustomizer.internal.SessionCookieCustomizer</code>

−

Currently, the fragment can be obtained from the [http://eclipse.org/rap/source/ RAP source code repository]: <code>runtime.ui/org.eclipse.rap.jettycustomizer</code>

+

Currently, the fragment can be obtained from the [http://eclipse.org/rap/source/ RAP source code repository]: <code>bundles/org.eclipse.rap.jettycustomizer</code>

=== How can i speed-up drawing on the GC? ===

=== How can i speed-up drawing on the GC? ===

Line 984:

Line 982:

In future RAP-releases the performance might improve, but it will probably never be as fast as in SWT.<br>

In future RAP-releases the performance might improve, but it will probably never be as fast as in SWT.<br>

Writing RAP Applications

I found a bug in RAP. Where should I report it?

Please report bugs or feature request in the Eclipse Bugzilla. See our Bugs page for details.

How to create a fullscreen application

use the style-bit SWT.NO_TRIM before creating the Shell. This will remove the title-bar, the minimize/maximize/close buttons and the ability for manually resizing the window.

overwrite the WorkbenchWindowAdvisor.postWindowCreate() method. Here we set the state of the Shell to maximized.

optional: depending on the requirements and complexity of our application it may be desirable to hide the menu bar by calling getWindowConfigurer().setShowMenuBar( false ). This is usually a good choice for small applications where the menu bar may not be needed.

How to access the HTTP session / session store?

Applies to RAP < 2.0

In RAP, the sessoin store is the preferred way to store information in the session context. However it also provides access to the HTTP session (see the code below). For working with session singletons, please use the SessionSingletonBase class.

How to integrate the Eclipse Help System in a RAP application?

After importing the example project, the following plugins have to be added, since they are not included in the RAP target:

javax.servlet.jsp

org.apache.commons.el

org.apache.commons.logging

org.apache.jasper

org.apache.lucene.analysis

org.apache.lucene

org.eclipse.equinox.jsp.jasper.registry

org.eclipse.equinox.jsp.jasper

org.eclipse.help.appserver

org.eclipse.help.base

org.eclipse.help.webapp

org.eclipse.help

The plug-ins mentioned above should be taken from a "suitable" Eclipse installation. Currently (RAP 1.2) this is version 3.4.

Please note that the included launch configuration must be used. It contains the -Dorg.eclipse.equinox.http.jetty.other.info=org.eclipse.help VM argument. Furthermore, the launch config assumes that the "RAP plug-ins" (...workbench etc.) are in your workspace. The target only contains the "Base plug-ins" (...equinox, ..core.runtime). In case your setup differs, you will need to adjust it.

Applies to RAP 1.3

As RAP 1.3 (starting from M2) delivers the infrastructure for the Help system, some of the facts above need to be adjusted. RAP itself only provides the core infrastructure for (like org.eclipse.help) but without the concrete implementation. This means you still need the plug-ins mentioned above (except org.eclipse.help). In case you don't need a sophisticed help solution (no dynamic help, no interaction with cheatsheets, no context help) the solution above is still sufficient. If you need better help integration (which is normally handled by org.eclipse.help.ui) you need to provide your own help ui contributions. This can be achieved by extending the org.eclipse.ui.helpSupport extension point.

The help system customization (like help window title or home page) in a RAP application is simply done by using the org.eclipse.core.runtime.products extension. Even if this extension is not fully supported by RAP, it is necessary to customize the help system. So:

2) create the product_customization.ini file in the root folder of my.plugin and add the needed configuration as specified by the product customization guide. For example it could contain:

# Toc ordering. Ordered list of help TOC's (books) as they would appear
# on the bookshelf. All the other TOCS will be following these books.
org.eclipse.help/baseTOCS=\
/my.plugin.ui.doc/toc.xml
# help system home page
org.eclipse.help.base/help_home=/my.plugin/doc/help_home.html

3) add the following VM argument to the launch configuration:

-Declipse.product=my.plugin.help_id

Building and deploying as web application

In order to make the help system available when building and deploying the RAP application as a web application, the following setting must be added to the WEB-INF/web.xml:

(analogue to setting the -Dorg.eclipse.equinox.http.jetty.other.info=org.eclipse.help in the launch configuration)

In order to add the help system customization when building and deploying the RAP application as a web application, the following setting must be added to the config.ini: eclipse.product=my.plugin.help_id (analogue to the -Declipse.product=my.plugin.help_id in the launch configuration.

Let's suppose that this action should be available only to users with role admin. We will create an expression-based activity demo.Activity1, which will be enabled when the variable demo.roles contains the string admin. Trough the associated pattern binding, the activity will control the availability of the demo.xyz.Action1 action and the corresponding menu item.

The value of the demo.roles variable is provided by a subclass of AbstractSourceProvider. A dummy implementation is shown below. The actual implementation should obtain the current user roles from a real authentication provider service.

What is a Session Singleton and how can I implement one?

A "session singleton" is an RWT-specific singleton, which provides access to a unique instance with session scope. This means that in the context of one user session getInstance() will always return the same object, but for different user sessions the returned instances will be different. RWT provides a utility to easily create session singletons, called SingletonUtil. Here's an example of a session singleton:

Note: the redirect servlet is needed here since registering a welcome page resource directly for the "/" alias does not work: a trailing slash would be appended to the resource URL.

I do ... in my bundle activator. Does not work as expected in RAP.

RAP differs from RCP in a way that RCP applications don't have to deal with session scopes but RAP applications have to. In RCP for example you can get access the one and only UI representation instance (your workbench) from every part of the code since application scope and session scope are implicitly the same.

Since you have a multi user environment in RAP (=> multiple Sessions at a time) but only one application wide equinox instance running which is shared between those sessions (application scope) things getting a little bit more complicated. Each session has its own workbench instance since the state of the UIs differ between sessions. So in principle you can easily access the core from the UI, but the other way round isn't possible without additional code.

So what's happening in your code is that you try to access your GUI layer (session scope) from the bundle activator (application scope), which isn't possible as was just explained. Most of the time it is easy to move the code from the activator to the EntryPoint#createUI or IStartup#earlyStartup. Both methods are executed in session scope context, so there won't be any IllegalStateExceptions thrown.

How to add a link to an external URL?

Since RAP 1.5, you can use simple HTML markup in a couple of widgets, including Label:

How to provide a download link?

To provide download functionality in a RAP (or pure RWT) application, you need two components:

a download link (see above)

a service handler (implementation of ServiceHandler) to provide the download content

Below is an example of a very basic downloads service handler. The request has a parameter "filename" which indicates which content (either static or dynamically generated) should be sent to the client. The MyDataStore will known how to find the required content. In our example the content is retrieved as byte[] but InputStreams and Readers can be easily accommodated as well.

How to switch locale/language on user action?

Switching the locale in a running session isn't supported out of the box. So currently you'll have to restart the session to be able to switch the locale.

To restart the session, we will send some Javascript code, which changes the parent.window.location.href DOM attribute of the current page. The new parent.window.location.href value is the URL of the current page plus a new parameter which contains the selected locale code.

Restarting the session and passing the new locale as a parameter

The changeLocale method is invoked when the user requests a language change (e.g. from a selection listener attached to a button). In order to add the page-reloading Javascript code to the HTTP response, we register a life-cycle PhaseListener:

Use java.awt.Graphics2D as a canvas on which to draw the image. The server, where the application will be deployed, most probably has no graphics UI system installed. Therefore we need to run AWT in "headless mode" by setting the system property java.awt.headless to true.

In the example below, the produced BufferedImage is placed in the UISession and the key is used to generate the new <img> tag for the Browser.

The service handler has to be registered with RWT.getServiceManager().registerServiceHandler() - see the first code snippet above. The handler receives the image key as a request parameter, and uses it to retrieve the image from the UISession.

How to deliver session-scoped resources

Often a RWT application UI includes session specific resources (e.g. images) - either because they are dynamically created or specific credentials are required to access them. This use case can be handled by a custom service handler and a Browser widget (or a custom widget). Please see the FAQ article #How_to_display_dynamically_created_images.3F for the implementation details.

How to access a RAP application without specifying a servlet name?

Let's suppose that we want to simplify the URL of our RAP application and be able to access it with http://www.example.org/webapp instead of http://www.example.org/webapp/servlet_path.

The recommended solution is to use a redirection servlet:

Write a servlet which redirects requests for the web application root to your application servlet path:

Sometimes it is more convenient to have the same URLs (i.e. the same context paths) in both deployment scenarios. Typically, the context path for a web application is assigned by the system administrator when the application is deployed or is inferred from the war file name.

For the embedded Jetty servlet container that is used by the RAP launcher, the context path can be specified as a VM parameter in the launch configuration:

-Dorg.eclipse.equinox.http.jetty.context.path=<context path>

In the launch configuration dialog, you should also change the Servlet name if the Open application in ... is checked.

How to update the UI from a background thread using Jobs?

Applications that wish to call UI code from a non-UI thread must provide a Runnable that calls the UI code. The methods syncExec(Runnable) and asyncExec(Runnable) in the Display class are used to execute these runnables in the UI thread during the event loop.

It is good practice to check if your widget is disposed from within the runnable when using Display#asyncExec(). Since other things can happen in the UI thread between the call to asyncExec and the execution of your runnable, you can never be sure what state your widgets are in by the time your runnable executes.

It's a fairly typical situation when a widget (e.g. Table) is populated with data retrieved from a database or some other external data source. The data source access code should not be ran in the UI thread in order to keep the UI responsive. The org.eclipse.core.runtime.jobs package provides an infrastructure for running concurrent operations (jobs) in a background threads.

In the following example a job is created to fetch some data from a mocked-up data store and to show the result in a Table. Since the Job runs in the background, the update of the TableViewer will be made from a Runnable executed via Display#asyncExec().

When using Jobs, the UI updates are pushed automatically to the client because the IProgressMonitor takes care of activating the UICallBack mechanism. The article #How_to_update_the_UI_from_a_background_thread.3F shows how to achieve similar functionality in a standalone RWT application.

How to update the UI from a background thread

Note: Since RAP 2.0 UICallBack has been replaced with ServerPushSession. Use ServerPushSession#start() and ServerPushSession#stop() to activate/deactivate it.

To allow automatic UI-updates by server side background threads the UI Callback needs to be activated. Call UICallBack#activate before the start of a thread and UICallBack#deactivate at the end. Each activation needs a session unique identifier as a kind of reference pointer to be able to decide when all background threads are finished.

The following steps outline the pattern:

activate the callback mechanism (must be done in the UI thread)

start background work

update the UI

deactivate the UI call-back.

The UI callback is activated by calling UICallBack.activate( "callback id" ), where the "callback id" is a session-unique identifier to trace the activation and deactivation. A typical use case is sketched below:

The actual changes to the UI must occur in the UI thread and are scheduled from the background thread by calling display.asyncExec(). As always is the case when updating UI from a background thread, we must check if the UI widget is not already disposed before using it. After the background work is done, we will disable the UI callback to free the aquired resources:

Technically, the UI callback is based on the long-polling technique. From the moment the UICallBack.activate() is called, the JavaScript client makes sure that there is always a pending request, waiting at the server to be processed. See the article Server push in RWT (aka UI Callback) for more details

How do I get notified when the browser window/tab is closed?

RAP does not provide a notification when the client's browser window/tab is closed. There is no reliable way to detect such an event that works across all browser. Instead, the servlet session timeout is used to detect whether the user has left the application.

If there is no activity, the HTTP session will time out after a pre-set time. Upon session timeout, all objects that are held by the session (e.g. the Workbench, the Display) will be released.

There are several ways to do some clean up before the session is destroyed. The first choice in most cases is to attach an SWT.Close listener to the Display or register a Runnable with disposeExec():

How do I implement a key binding that triggers a Command?

Since 1.4 M7, RAP supports key bindings in plain RWT applications by attaching a list of active key bindings to the display using Display.setData with RWT.ACTIVE_KEYS as key (see bug bug 343248).
For details, please refer to the JavaDoc of RWT.ACTIVE_KEYS.

Note: The solution below only applies only to earlier versions.

First, you need to register some Javascript code to attach a key event listener to the qooxdoo ClientDocument. In this example, the key listener checks for the key sequence Ctrl+1 and sends a request with a custom request parameter if these keys are pressed.

That's it. The Command with the id my.command.id is triggered when the registered key event sent the parameter PARAMETER_KEY_PRESSED with the value "true". As an improvement, you could also listen for different key sequences to trigger different commands.

How to integrate Equinox Security/JAAS in RAP?

How to run a RAP application in multiple browser tabs/windows?

Since RAP 2.1, multiple browser tabs are supported without any modifications (see bug 390236 for details).
The following discussion is still valid for RAP versions prior to 2.1.

By default, servlet engines use cookies to identify a session. Browsers usually re-use the same session cookie for all tabs and windows within the same process. In the end, the RAP servlet cannot distinguish request that come from the same browser/client-session and rejects request that come from a second tab or window with the message "Multiple browser-instances or browser-tabs per session are not supported. You may click OK for restarting the session.". For a complete history of this issue, please see bug 285398.

The solution is to disable the use of cookies for session-identification of the servlet engine. For instruction on how to configure Tomcat and Jetty, read the sections below.

Tomcat

(tested with version 5.5 and 6.0) In the META-INF folder of your web application, place a context.xml file with the following content:

<Contextcookies="false"></Context>

The cookies=false attribute causes Tomcat to not use cookies to identify a session, and rely only on URL rewriting by the application (RAP in this case).

Upon deployment of the WAR, the context.xml will be copied to an appropriate place under the conf folder. Once this file exists, it will not be replaced if a new WAR with a newer META-INF/context.xml is deployed. For further implications and more detailed information, please read the Apache Tomcat Configuration Reference

Jetty

This applies only to running RAP with standalone Equinox using the Jetty-based HttpService (e.g. launching a RAP application from within the IDE).

To enable tabbed browsing with Jetty, a so-called JettyCustomizer is needed. The org.eclipse.rap.jettycustomizer fragment bundle contains an implementation that instructs Jetty to not use cookies to identify a session, and rely only on URL rewriting by the application (RAP in this case).

For the customizer to be picked up when Jetty is started, the following system property must be specified: -Dorg.eclipse.equinox.http.jetty.customizer.class=org.eclipse.rap.jettycustomizer.internal.SessionCookieCustomizer

How can i speed-up drawing on the GC?

The RAP GC-implementation is only suited for relatively simple or static graphs. This is especially true for Internet Explorer which slows down significantly after about 200 drawing operations. Other browser can manage much more (depending on the clients hardware-resources), but will still need a very noticeable amount of time after a couple of hundred operations. Currently the only way to speed-up drawing is to reduce the number of drawing-operations as much as possible:

Consider removing purely decorative elements.

If possible, use drawPolyLine instead of multiple drawLine operations.

If you have areas in your graph that change independently from each other, use one canvas for each of these areas instead of one big canvas.

If you have completely static elements, you can also set a background-image on the canvas and draw the dynamic elements above this image.

In future RAP-releases the performance might improve, but it will probably never be as fast as in SWT.

On my Tree or Table the item or cell background is not drawn when the row is hovered or selected.

This is the default behavior for all RAP versions until 1.4, and can not be changed. For RAP 1.5 this is still the default, but can be changed by theming.
The default (or buisness) theme uses the TreeRow-Overlay/TableRow-Overlay elements to render the hover and selection state. These are painted over the item itself.

To change this, make a theme contribution are custom theme that looks like this:

Tree is the same, just with TreeItem and TreeRow-Overlay. You can also mix and use overlay only for selection, but item for hover. In that case selection overwrites the item colors, but not the hover.

On my Tree or Table the selection or hover effect is hidden on items with background color.

This happens if you make a custom theme that does not use the TableRow-Overlay/TreeRow-Overlay element with RAP 1.5. In your custom theme, replace all occurrence of TableItem/TreeItem that use selection/hover states with TableRow-Overlay/TreeRow-Overlay.

Deployment

Problems using Import-Package header

Since RAP 1.1 the workbench introduced a concept of so-called "split packages". This is a way of OSGi to have virtual packages which are physically split across several bundles. See this post and the OSGi 4.1 specification (§3.13.3) for more information about split packages.

A common problem with them is that a split-package is only resolved when there is at least one additional split part available during runtime. As the RAP infrastrcuture only contains the workbench bundle at the moment this constrain is not met. In RCP world you often have the org.eclipse.ui.ide bundle available which contributes to these split packages and let Equinox resolve the constrains.

In order to work around this problem you are able to import only a certain part of the package (the part of the workbench in our example). You just need to extend your Import-Package declaration with the split attribute as shown in the following MANIFEST.MF fragment:

you may want to add a port after -console in unix environments, you can then telnet to the OSGi console

type ss in the console and see if all bundles are started. If not try starting them with "start <bundle-id>". The stack traces may hint to what is missing

make sure that there is a org.eclipse.equinox.servletbridge.extensionbundle in the ss-listing whos state is RESOVLED

Make sure that the WAR does not contain the javax.servlet bundle because it is provided by the hosting servlet container. If your code depends on classes from javax.servlet, hte dependency must be expressed as an Import-Package. Do not list javax.servlet as a Require-Bundle.

Make sure that the WAR does not contain the org.eclipse.update.configurator bundle.

The WAR contains compile errors. You will probably find a zip archive somewhere in your output folder. It contains log files with the compiler output.

Start with a working example: rapdemo.war and integrate your plug-ins.

Use the product export to validate your feature:

Create a product configuration with an arbitrary name (File > New > Other > Product Configuration)

Select "The product configuration is based on features" on the "Overview" page

Add your feature to the list of features on the "Dependencies" page

Press the Validate' button in the top-left corner of the editor. Ignore complaints about missing javax.servlet packages. Be aware that unresolved optional dependencies aren't reported as errors.

If you are re-deploying, make sure to delete the work directory of your servlet engine (e.g. <tomcat_install>/work/Catalina/localhost/work/<webapp_name> in Tomcat)

How do I make remote calls to EJB's deployed on Jboss 4.x AS

This is not a solution for calling local interface EJB's (I wasn't able to do it :( ), neither for EJB3 specification (didn't tried yet)

Nevertheless is more useful to make remote calls as the RAP application and the JBoss AS could be on separate machines (or will be sometime in the application life-cycle)

prepare a jar with EJB's interfaces which you are about to call from RAP (I think here you may use it wrapped as a bundle if you want to separate it from your application bundle)

put the jar in the application runtime classpath or add it as a dependency plugin if you use it as a bundle

How do I develop an RWT standalone application with RAP <= 1.4

To use the RWT standalone application in Tomcat follow the steps below:

Create a new Java project.

In the project create the folders:

WEB-INF

WEB-INF/lib

WEB-INF/classes

In the WEB-INF folder, place a file named web.xml with the content below:

<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"version="2.4"><display-name>Welcome to RWT</display-name><description>Welcome to RWT</description><context-param><param-name>org.eclipse.rwt.entryPoints</param-name><param-value>com.example.HelloWorld</param-value></context-param><listener><listener-class>org.eclipse.rwt.internal.engine.RWTServletContextListener</listener-class></listener><servlet><servlet-name>rwtServlet</servlet-name><servlet-class>org.eclipse.rwt.internal.engine.RWTDelegate</servlet-class></servlet><servlet-mapping><servlet-name>rwtServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping></web-app>

You can use several features (e.g. branding, theming) that are usually specified with extension points by using context parameters.

ZIP the the WEB-INF folder (including the folder itself) as RWT_Standalone.war.

Deploy the RWT_Standalone.war in Tomcat.

Start the standalone RWT application from:

http://<host>:<port>/RWT_Standalone/main

If you get an IllegalArgumentException or a ClassNotFoundException after deploying your application, please check first the contents of your WAR file. Maybe it doesn't contain all class files.

How do I develop an RWT standalone application with RAP >= 1.5

It is recommended to use the RAP Tooling for developing RWT applications. Though it is not stricly necessary to use the tooling, it eases development with a launch configuration tailored for RWT applications and documentation.

Follow the steps outlined below and you will have a simple web application up and running in a few minutes.

Create a Java Project (or a plug-in project if you prefer and if you are familiar with plug-in development)

Configure the project to match the layout of a web application. You may skip or postpone this step if you are using RAP Tooling to launch the application. The layout is neccessary if you want to deploy the project as a WAR.

Create the three folders: WEB-INF, WEB-INF/lib, WEB-INF/classes

Change the projects' output folder to WEB-INF/classes.

Copy the org.eclipse.rap.rwt_* jar from the RAP Runtime into the WEB-INF/lib folder and add it to the projects' build path. The org.eclipse.rap.rwt.source_* jar contains the RWT source code. To be able to browse the sources and read JavaDoc, specify this jar as the Source Attachment

With the RAP Tooling installed, you can already launch your HelloWorld application. To do so, select the HelloWorld class (i.e. in the Package Explorer) and choose Run As > RWT Application from the context menu.

If you whish to deploy your application on an external servlet engine, or if you need a deployment descriptor for other reasons, or if you haven't installed the RAP Tooling, a few more steps are required to run the application.

Place a deployment descriptor (web.xml) in the WEB-INF folder with the content below:

Again you can use the RAP Tooling to launch the application from the just created web.xml. To do so, create a new RWT Launch Configuration and select "Run from web.xml". Enter the location of the web.xml file and specify "hello" as the servlet path.

You may also find the JFace components useful. In order to use them from RWT standalone, you will need to add the following jars from the RAP Runtime:

org.eclipse.rap.jface

org.eclipse.core.runtime

org.eclipse.core.commands

org.eclipse.equinox.common

Why are there encoding issues after deploying my RAP application as a WAR?

The pde.exportFeatures Ant task uses the encoding specified in file.encoding system property, which might not match the encoding of your source files. You can change this behaviour by explicitly defining the encoding used in pde.exportFeatures task. Just identify the plugin, which contains the strings with non-ASCII characters, and add javacDefaultEncoding property to his build.properties file.

The following example sets the encoding to utf-8, but you should specify whatever encoding your source files are using:

I cannot access resource/image after deploying as a WAR

The image/resource is visible when running from within the IDE but is missing after deploying.

All resources must be explicitly listed in the bin.includes variable or they will not be included in the binary distribution of your plug-in. Please verify your build.properties files to ensure that your plug-ins are not missing any entries for images and other resource files.

How do I stress test or load test my RAP application

How can I test my application with HTTPS?

When running a RAP application from the IDE, the Jetty servlet container is used. Jetty can simply be put into HTTPS mode:

First you need to create a certificate using the keytool from the Java SDK:

# keytool -keystore keystore -alias jetty -genkey -keyalg RSA
Enter keystore password: password
Re-enter new password: password
What is your first and last name?
[Unknown]: RAP Example
What is the name of your organizational unit?
[Unknown]: RAP Team
What is the name of your organization?
[Unknown]: Eclipse
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN=RAP Example, OU=RAP Team, O=Eclipse, L=Unknown, ST=Unknown, C=Unknown correct?
[no]: yes
Enter key password for <jetty>
(RETURN if same as keystore password):

Where to find translations/language packs?

Translations for RAP can be found at the Babel project: It provides community translated language packs for the majority of the Eclipse projects.

How do I use GZip compression with the Equinox HttpService?

Contemporary servlet engines provide for transparently compressing the response content. However, the methods used to enable this feature are container-specific. Here is an example for a Tomcat connector declaration in server.xml:

When deploying RAP as standalone server (as opposed to deploying it in a WAR) the servlet engine is hidden behind the HttpService.

RAP by default ships with Equinox for the OSGi implementation and Equinox in turn uses Jetty behind the HttpService. This allows to configure the Jetty GzipFilter. The following applies to RAP running on Equinox 3.6 or later and Jetty 6.2.x.

For the GzipFilter class to be found, the plug-in that defines the extension must depend on org.mortbay.jetty.util

For those who prefer using OSGi services the filter can also be registered with the org.eclipse.equinox.http.servlet.ExtendedHttpService.

How to add a custom error page to a web application

The Equinox BridgeServlet has to be registered with a path mapping, i.e. a pattern that begins with a / and ends with a /*.
Usually, it is mapped to /*. But this mapping prevents any other path mappings from taking effect.

To add a custom error page to an application, the BridgeServlet can be mapped to a path like /foo/*.
Here's an example:

The HTTP 404 error code will be served by your custom error page error404.html, which resides in the root directory of the webapp.

Branding and Theming

How to activate the Classic Theme?

To activate the classic theme add the bundle org.eclipse.rap.rwt.theme.classic to an exsiting launch configuration and change the servlet name to "classic". An alternative way to use the classic theme is to create an own branding and set the themeId to org.eclipse.rap.rwt.theme.classic.

How can I use an image in the branding body?

Using a user-defined resource inside of a RAP application requires registering it in some way. In case of images used inside the branding body, this can be done declaratively using the org.eclipse.equinox.http.registry.resources extension.

Assume you have a folder branding in the root of your plugin, containing an image called loading.gif. Add the following code to your plugin.xml:

This maps the provided resource base name to the given alias name and makes it available for use.

Access the image in your branding body by referring to the alias name:

...
<imgsrc="./loading.gif"border="0"/>
...

Why doesn't RAP simply use CSS for styling, such as e.g. GWT?

In GWT for example, every widget has a configurable style name that is rendered as class attribute. Styling is done by adding a CSS file to the target HTML document. Although this is a simple technique, it does not work out for RAP for a number of reasons:

1. One of the main objectives of RAP is to prevent vendor lock-in by allowing for exchangeable client implementations. Although our current client-side technique is based on JavaScript, there are completely different technologies out there that might be interesting candidates for RAP clients (GWT, Flex, Silverlight ...). Not all of those technologies can necessarily deal with CSS.

2. In RAP, all layouts are computed on the server side, thus the server also needs to know about any variable dimensions like paddings and borders. This is not possible if a style sheet is applied only on the client side.

3. Due to browser bugs and differences, writing cross-browser CSS code is a complex task. Client technologies may work around those browser issues. In fact, the qooxdoo library does so.

How can I change the favicon / title of my RAP app?

With the help of RAPs branding features you're able to define several (visual) aspects of your RAP application. This includes for example the page title which is shown in the browser, the favicon or the theme to be used for the application. See the Branding section of the RAP Developer guide for details.

Single Sourcing

Why does Display#getDefault() work different than in SWT

One notable difference between SWT and RWT is the way the UI thread is determined. In SWT, calling new Display() marks the thread that executes the code as the UI thread. This means that the programmer is free to choose which thread should become the UI thread.

RWT, on the contrary, already provides the one and only UI thread before createUI is called (the equivalent to the main method). As a consequence, getDefault() can only create a Display instance if it is called from the user-interface thread.

How do I setup dependencies on org.eclipse.rap.ui bundles for single sourcing?

The shared package structure between org.eclipse.ui and org.eclipse.rap.ui bundles requires that dependencies be specified either via package-import or require-bundle in the bundle manifest. When single sourcing using require-bundle, it is necessary to mark the bundles as optional that are specific to either target platform, (e.g., org.eclipse.ui and org.eclipse.rap.ui). When using package-import be cautious of split-packages, see this thread for more info.

Why can't I remove warnings for missing org.eclipse.ui bundles?

Using require-bundle as mentioned above will produce warnings regarding the missing optional bundles. One method of removing these warnings is to create empty bundles that have the same bundle name and version so that they act as stubs for those that are missing.

Troubleshooting

My application is not running after switching to RAP 1.5

The RAP 1.5 runtime contains an additional bundle named org.eclipse.rap.rwt.osgi.
You need to include it in your launch configuration to be able to run a workbench-based application.

The Equinox console also requires three new bundles from the Apache Gogo project:
org.apache.felix.gogo.command,
org.apache.felix.gogo.runtime, and
org.apache.felix.gogo.shell.
These new bundles are contained in the basic RAP target.

IllegalStateException: No context available outside of the request service lifecycle

Your code tries to access session-information but isn't run from the UI thread (the only thread that has a session context associated by default).

The soltion is to wrap your code in a Runnable and have it executed by UICallBack#runNonUIThreadWithFakeContext().

Unfortunately, Firefox and Chrome seem to more tolerant with these errors than Internet Explorer.

Locale fallback does not work as expected

You created a messages.properties file and several messages_XX.properties files for different locales. You expect the system to use the messages.properties file as a fallback when no messages_XX.file is found for the locale in question.

But that's not how RWT works. If a properties file is not found for the locale in question, RWT tries the default locale, i.e. Locale.getDefault(). This is usually the VM's locale. So if your VM is set to German, and there is a messages_de.properties file, you'll get German. If you want to have English as your fallback, set your VM to English.