Twitter Logo Follow us on Twitter
Project Information About this project

RAP 2.3 M2 - New and Noteworthy

Here's a list of the most noteworthy things in the RAP 2.3 M2 milestone build which is available for download since March 14, 2014.

Heads up: Webkit bug, affects Chrome, Safari and Opera

Recently, a bug has been introduced in WebKit that leads to RAP UIs becoming partly invisible when a Canvas widget is included. This problem also affects earlier versions of RAP running in recent WebKit-based browsers. A workaround is outlined in bug 428717, but didn't make it into this milestone. We're confident to include it in M3. For older versions of RAP, please visit the FAQ for workarounds that you can apply yourself.

Drag&Drop Support for Client Files

You can now allow users to upload files from their desktop by dropping them onto a widget. To do so, you use the SWT Drag&Drop API with the transfer type ClientFileTransfer. The following example shows how to enable a Label to accept files:

Label dropLabel = new Label( parent, SWT.BORDER );
dropLabel.setText( "Drop files here" );
DropTarget dropTarget = new DropTarget( dropLabel, DND.DROP_MOVE );
dropTarget.setTransfer( new Transfer[]{ ClientFileTransfer.getInstance() } );
dropTarget.addDropListener( new DropTargetAdapter() {
  @Override
  public void drop( DropTargetEvent event ) {
    filesDropped( (ClientFile[])event.data );
  }
} );

The event.data field will contain an array of ClientFiles, that provide information on the dropped files. It's an array because the user can also select and drag multiple files. To actually upload the dropped files, the new client service ClientFileUploader can be used:

ClientFileUploader uploader = RWT.getClient().getService( ClientFileUploader.class );
uploader.submit( uploadUrl, clientFiles );

Finally, you have to accept and store the files on the server. The fileupload component in the RAP Incubator can be used to handle uploads in RAP easily. The FileDialog, also in the RAP Incubator, now also accepts dropped files.

New API for Singletons

We already provide the class SingletonUtil to facilitate the conversion of classic singletons to UISession-scoped singletons for use in RAP's multi-user environment. This class has a new method named getUniqueInstance that accepts a UISession instance as a parameter. You can obtain a unique instance of a given class for the current UISession like so:

public static MySingleton getInstance() {
  UISession uiSession = RWT.getUISession();
  return SingletonUtil.getUniqueInstance( MySingleton.class, uiSession );
}

In this case, the method is equivalent to the existing method getSessionInstance(). However, with the additional parameter, it allows you to obtain the singleton instance for a given UISession even from another thread without having to wrap your code in a runnable and pass it to uiSession.exec(). To prepare your singleton for access from background threads, you may consider adding a parameter to the getInstance method as shown below. This pattern also allows for better unit tests.

private static MySingleton getInstance( UISession uiSession ) {
  return SingletonUtil.getUniqueInstance( MySingleton.class, uiSession );
}

The old method getSessionInstance() still exists and delegates to the new one, so you should be able to adjust your code using an “Inline Method” refactoring.

Support for Application Singletons

Similar to UISession singletons, you can now also create singletons with application scope. Whenever you run multiple RAP applications in a single VM, there may be classes in a shared bundle that should have exactly one instance per application.

ApplicationContext context = RWT.getApplicationContext();
SingletonUtil.getUniqueInstance( MySingleton.class, applicationContext );

Bugfixes

This list shows all bugs that have been fixed for this milestone build.

Previous Builds

The above features are just the ones that are new since the last milestone build. Summaries for earlier builds: