Enable AutoSuggest to handle events fired before the model is created

Text and DropDown can fire events before the model object exists,
(caused by protocol operations), in which case the client would crash.
They are now delayed until the objects are created, which must be in the
same request - otherwise the client still crashes, which is correct.
diff --git a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/EventDelegator.js b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/EventDelegator.js
index 70e00da..4fc4420 100644
--- a/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/EventDelegator.js
+++ b/bundles/org.eclipse.rap.addons.autosuggest/src/org/eclipse/rap/addons/autosuggest/internal/resources/EventDelegator.js
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 EclipseSource.
+ * Copyright (c) 2013, 2014 EclipseSource.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -9,7 +9,7 @@
  *    EclipseSource - initial API and implementation
  ******************************************************************************/
 
-//@ sourceURL=DataBinding.js
+//@ sourceURL=EventDelegator.js
 
 ///////////////////
 // Event Delegation
@@ -17,8 +17,22 @@
 var MODEL_KEY = "org.eclipse.rap.addons.autosuggest#Model";
 
 function handleEvent( event ) {
-  var model = rap.getObject( event.widget.getData( MODEL_KEY ) );
-  var autoSuggestListener
-    = rwt.remote.ObjectRegistry.getObject( model.get( "autoSuggestListenerId" ) );
-  autoSuggestListener( event );
+  withObject( event.widget.getData( MODEL_KEY ), function( model ) {
+    var autoSuggestListener
+      = rwt.remote.ObjectRegistry.getObject( model.get( "autoSuggestListenerId" ) );
+    autoSuggestListener( event );
+  } );
+}
+
+function withObject( id, callback ) {
+  // compensating for the server creating the objects in the wrong order:
+  if( rap.getObject( id ) ) {
+    callback( rap.getObject( id ) );
+  } else {
+    var wrapper = function() {
+      callback( rap.getObject( id ) );
+      rap.off( "render", wrapper );
+    };
+    rap.on( "render", wrapper );
+  }
 }