Class WJavaScriptHandle<T extends WJavaScriptExposableObject>

java.lang.Object
eu.webtoolkit.jwt.WJavaScriptHandle<T>

public class WJavaScriptHandle<T extends WJavaScriptExposableObject> extends Object
A handle to a JavaScript representation of an object.

A WJavaScriptHandle allows to access and modify an object in JavaScript. This is useful to avoid server roundtrips when frequently updating something, e.g. to interact with and animate a WPaintedWidget.

You can use the value of a WJavaScriptHandle just as you would normally, with the exception that it will be JavaScript bound and so will any copies you make of it. You should not modify a JavaScript bound object, as this will not change its client side representation. Use the handle's setValue(T) method instead.

You can access (and modify) the value of a handle on the client side using getJsRef().

You can update the value from the server with setValue(T). Currently, changes made to the value on the client side are not synced back to the server, but support may be added for this in the future.

Currently, only WPaintedWidget allows the use of JavaScript exposable objects.

See Also:
  • Method Details

    • getJsRef

      public String getJsRef()
      Returns the JavaScript representation of the object.

      You can access and modify the value of this handle through its jsRef.

      Changes on the client side are currently not synced back to the server, but support for this may be added in the future.

    • setValue

      public void setValue(T value)
      Set the value for this handle.

      The value may not be JavaScript bound, i.e. related to another WJavaScriptHandle.

      The change to the value will be synced to the client side equivalent.

      A defensive copy will be made of given value.

      Throws:
      NullPointerException - The given value is null
      WException - Trying to assign a JavaScript bound value
    • getValue

      public T getValue()
      Get the value for this handle.

      Returns:
      A copy of the value.

      Warning: You should not modify this value or any copy of it on the server side, because this will not be synced to the client side. Use setValue(T) instead.