Wt  3.7.1
Public Member Functions | List of all members
Wt::WJavaScriptHandle< T > Class Template Reference

A handle to a JavaScript representation of an object. More...

#include <Wt/WJavaScriptHandle>

Public Member Functions

 WJavaScriptHandle ()
 Create an invalid WJavaScriptHandle. More...
 
 WJavaScriptHandle (const WJavaScriptHandle &handle)
 Copy constructor.
 
WJavaScriptHandleoperator= (const WJavaScriptHandle &handle)
 Copy assignment operator.
 
bool isValid () const
 Returns whether this is a valid handle. More...
 
std::string jsRef () const
 Returns the JavaScript representation of the object. More...
 
void setValue (const T &v)
 Set the value for this handle. More...
 
const T & value () const
 Get the value for this handle. More...
 

Detailed Description

template<typename T>
class Wt::WJavaScriptHandle< T >

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() method instead.

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

You can update the value from the server with setValue(). Changes on the client side will be synced back to the server.

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

See also
WJavaScriptExposableObject, WPaintedWidget

Constructor & Destructor Documentation

◆ WJavaScriptHandle()

template<typename T>
Wt::WJavaScriptHandle< T >::WJavaScriptHandle ( )

Create an invalid WJavaScriptHandle.

The handle will be invalid until a valid WJavaScriptHandle is copy-assigned to it.

Member Function Documentation

◆ isValid()

template<typename T>
bool Wt::WJavaScriptHandle< T >::isValid ( ) const

Returns whether this is a valid handle.

A handle is not valid if it is not connected to a JavaScript representation. To make a WJavaScriptHandle valid, a valid WJavaScriptHandle has to be copy-assigned to it. The various createJS... methods in WPaintedWidget return a valid handle.

◆ jsRef()

template<typename T>
std::string Wt::WJavaScriptHandle< T >::jsRef ( ) const

Returns the JavaScript representation of the object.

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

Exceptions
WExceptionThe handle is invalid

◆ setValue()

template<typename T>
void Wt::WJavaScriptHandle< T >::setValue ( const T &  v)

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.

Exceptions
WExceptionThe handle is invalid
WExceptionTrying to assign a JavaScript bound value

◆ value()

template<typename T>
const T& Wt::WJavaScriptHandle< T >::value ( ) const

Get the value for this handle.

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() instead.
Exceptions
WExceptionThe handle is invalid

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13