Class JSOHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic JavaScriptObject
addProperties
(JavaScriptObject destination, JavaScriptObject propertiesObject) Adds all properties and methods from the propertiesObject to the destination object.static void
apply
(JavaScriptObject config, JavaScriptObject jsObj) static JavaScriptObject
arrayConvert
(JavaScriptObject[] array) static JavaScriptObject
arrayConvert
(Object[] array) static Object
arrayGetObject
(JavaScriptObject array, int index) static int
arrayLength
(JavaScriptObject array) static void
arraySet
(JavaScriptObject array, int index, JavaScriptObject value) static void
arraySet
(JavaScriptObject array, int index, Object value) static Object
callMethod
(JavaScriptObject target, String methodName, Object[] arguments) Invoke a method on some JavaScript object, passing in the specified array of parameters.static JavaScriptObject
cleanProperties
(JavaScriptObject properties, boolean copyProperties) Removes non-transferable properties from the supplied object (e.g.static JavaScriptObject
convertMapToJavascriptObject
(Map valueMap) Converts the parameter Map to an equivalent Javascript object - seeJavaToJavaScriptConversion
for details of the conversions that take place.static JavaScriptObject
convertMapToJavascriptObject
(Map valueMap, boolean strict) static Object[]
convertToArray
(JavaScriptObject object) Convert a JavaScript object to an Object[], following the rules described in theJS -> Java conversion article
.static JavaScriptObject
convertToCellArray
(int[][] cells) static Object
convertToJava
(JavaScriptObject object) Convert a JavaScriptObject to the appropriate type of Java Object, following the rules described in theJS -> Java conversion article
.static Object
convertToJava
(JavaScriptObject object, boolean listAsArray) Convert a JavaScriptObject to the appropriate type of Java Object, following the rules described in theJS -> Java conversion article
static Boolean[]
static Date
static Date[]
static Double[]
static Float[]
static int[]
static Integer[]
static Integer[]
Deprecated.static Object[]
static RefDataClass[]
convertToJavaRefDataClassArray
(JavaScriptObject nativeArray) static JavaScriptObject
convertToJavaScriptArray
(boolean[] array) static JavaScriptObject
convertToJavaScriptArray
(byte[] array) static JavaScriptObject
convertToJavaScriptArray
(char[] array) static JavaScriptObject
convertToJavaScriptArray
(double[] array) static JavaScriptObject
convertToJavaScriptArray
(float[] array) static JavaScriptObject
convertToJavaScriptArray
(int[] array) static JavaScriptObject
convertToJavaScriptArray
(long[] array) static JavaScriptObject
convertToJavaScriptArray
(short[] array) static JavaScriptObject
convertToJavaScriptArray
(Object[] array) Converts the parameter Object array to an equivalent Javascript array - seeJavaToJavaScriptConversion
for details of the conversions that take place.static JavaScriptObject
convertToJavaScriptArray
(Object[] array, boolean strict) static JsDate
convertToJavaScriptDate
(Date date) static String[]
static <O extends JavaScriptObject>
JsArray<O>convertToJsArray
(O[] array) static List
convertToList
(JavaScriptObject object) Convert a JavaScript object to a List, following the rules described in theJS -> Java conversion article
.static Map
convertToMap
(JavaScriptObject jsObj) Convert a JavaScript object containing key:value pairs to a Java Map, following the rules described in theJS -> Java conversion article
.static Map
convertToMap
(JavaScriptObject jsObj, boolean listAsArray) Convert a JavaScript object containing key:value pairs to a Java Map, following the rules described in theJS -> Java conversion article
static String
convertToString
(Object obj) static JavaScriptObject
static JavaScriptObject
static void
deleteAttribute
(JavaScriptObject elem, String attr) static void
deleteAttributeIfExists
(JavaScriptObject elem, String attr) static double
doubleValue
(Number num) static JavaScriptObject
Evaluate the passed string as Javascriptstatic int
getArrayLength
(JavaScriptObject array) static String
getArrayValue
(JavaScriptObject array, int index) static String
getAttribute
(JavaScriptObject elem, String attr) static boolean
getAttributeAsBoolean
(JavaScriptObject elem, String attr) Returns attribute value set as a Boolean.static Boolean
getAttributeAsBoolean
(JavaScriptObject elem, String attr, boolean allowNull) Returns attribute value set as a Boolean.static Date
getAttributeAsDate
(JavaScriptObject elem, String attr) static Double
getAttributeAsDouble
(JavaScriptObject elem, String attr) static double[]
getAttributeAsDoubleArray
(JavaScriptObject elem, String attr) static Element
getAttributeAsElement
(JavaScriptObject elem, String attr) static Float
getAttributeAsFloat
(JavaScriptObject elem, String attr) static Integer
getAttributeAsInt
(JavaScriptObject elem, String attr) static int[]
getAttributeAsIntArray
(JavaScriptObject elem, String attr) static JavaScriptObject
getAttributeAsJavaScriptObject
(JavaScriptObject elem, String attr) static JavaScriptObject[]
static Map
getAttributeAsMap
(JavaScriptObject elem, String attr) Returns attribute "attr" of JavaScriptObject "elem", converted to a Map following the rules described in theJS -> Java conversion article
static Object
getAttributeAsObject
(JavaScriptObject elem, String attr) static String[]
getAttributeAsStringArray
(JavaScriptObject elem, String attr) static Boolean
getBooleanArrayValue
(JavaScriptObject array, int index) static int[][]
getCellArray
(JavaScriptObject jsCells) static String
getClassName
(JavaScriptObject javaScriptObject) Returns the javascript class name.static Date
getDateArrayValue
(JavaScriptObject array, int i) static double
getdoubleArrayValue
(JavaScriptObject array, int index) static Double
getDoubleArrayValue
(JavaScriptObject array, int index) static double
getDoubleValueFromJavaScriptObjectArray
(JavaScriptObject elem, int i) static Element
getElementValueFromJavaScriptObjectArray
(JavaScriptObject elem, int i) This is used to access Element array as JavaScriptObjectstatic float
getfloatArrayValue
(JavaScriptObject array, int index) static Float
getFloatArrayValue
(JavaScriptObject array, int index) static int
getIntArrayValue
(JavaScriptObject array, int index) static Integer
getIntegerArrayValue
(JavaScriptObject array, int index) static int
getIntValueFromJavaScriptObjectArray
(JavaScriptObject elem, int i) static int
static JsDate
getJSLogicalDate
(int year, int month, int date) static JsDate
getJSLogicalDate
(Date date) static JsDate
getJSLogicalTime
(int hour, int minute, int second, int millisecond) static JsDate
getJSLogicalTime
(Date date) static JavaScriptObject
getJSOArrayValue
(JavaScriptObject array, int index) static Object
getObjectArrayValue
(JavaScriptObject array, int index) static String[]
getProperties
(JavaScriptObject jsObj) static String
static String
getStringValueFromJavaScriptObjectArray
(JavaScriptObject elem, int i) static JavaScriptObject
getValueFromJavaScriptObjectArray
(JavaScriptObject elem, int i) static boolean
isArray
(JavaScriptObject jsObj) static boolean
isJavaArray
(Object obj) static boolean
isJavaBoolean
(Object obj) static boolean
isJavaDate
(Object obj) static boolean
isJavaDouble
(Object obj) static boolean
isJavaFloat
(Object obj) static boolean
isJavaInteger
(Object obj) static boolean
isJavaList
(Object obj) static boolean
static boolean
isJavaNumber
(Object obj) static boolean
isJavaString
(Object obj) static boolean
static boolean
isScClassInstance
(JavaScriptObject javaScriptObject) Returns whether the supplied JavaScriptObject is a SmartClient class instance.static boolean
isScClassObject
(JavaScriptObject javaScriptObject) Returns whether the supplied JavaScriptObject is a SmartClient class (a Class object itself, rather than an instance of a class).static JavaScriptObject[]
listToArray
(List list) static void
setArrayValue
(JavaScriptObject array, int index, boolean value) static void
setArrayValue
(JavaScriptObject array, int index, char value) static void
setArrayValue
(JavaScriptObject array, int index, double value) static void
setArrayValue
(JavaScriptObject array, int index, long value) static void
setArrayValue
(JavaScriptObject array, int index, JavaScriptObject value) static void
setArrayValue
(JavaScriptObject array, int index, Object value) static void
setArrayValue
(JavaScriptObject array, int index, String value) static void
setArrayValue
(JavaScriptObject array, int index, Date value) static void
setAttribute
(JavaScriptObject elem, String attr, boolean value) static void
setAttribute
(JavaScriptObject elem, String attr, double value) static void
setAttribute
(JavaScriptObject elem, String attr, double[] values) static void
setAttribute
(JavaScriptObject elem, String attr, float[] values) static void
setAttribute
(JavaScriptObject elem, String attr, int value) static void
setAttribute
(JavaScriptObject elem, String attr, int[] values) static void
setAttribute
(JavaScriptObject elem, String attr, JavaScriptObject value) static void
setAttribute
(JavaScriptObject elem, String attr, JavaScriptObject[] value) static void
setAttribute
(JavaScriptObject elem, String attr, Function handler) static void
setAttribute
(JavaScriptObject elem, String attr, ValueEnum[] values) static void
setAttribute
(JavaScriptObject elem, String attr, Boolean value) static void
setAttribute
(JavaScriptObject elem, String attr, Boolean[] values) static void
setAttribute
(JavaScriptObject elem, String attr, Double[] values) static void
setAttribute
(JavaScriptObject elem, String attr, Float[] values) static void
setAttribute
(JavaScriptObject elem, String attr, Integer[] values) static void
setAttribute
(JavaScriptObject elem, String attr, Long value) static void
setAttribute
(JavaScriptObject elem, String attr, Long[] values) static void
setAttribute
(JavaScriptObject elem, String attr, Number value) static void
setAttribute
(JavaScriptObject elem, String attr, Object value) Set the value of attribute "attr" in object "elem" to the Object "value"static void
setAttribute
(JavaScriptObject elem, String attr, String value) static void
setAttribute
(JavaScriptObject elem, String attr, String[] values) static void
setAttribute
(JavaScriptObject elem, String attr, Date value) static void
setAttribute
(JavaScriptObject elem, String attr, Date[] values) static void
setAttribute
(JavaScriptObject jsObj, String attr, Map valueMap) Sets attribute "attr" on Javascript object "jsObj" to the JavaScript equivalent of "valueMap".static void
setNullAttribute
(JavaScriptObject elem, String attr) static void
setObjectAttribute
(JavaScriptObject elem, String attr, Object object) static void
throwUnconvertibleObjectException
(Object object, String messageDetail) static JavaScriptObject[]
toArray
(JavaScriptObject array) static Boolean
toBoolean
(boolean value) static Date
toDate
(double millis) Converts a time to a JavaDate
object.static JavaScriptObject
static Double
toDouble
(double value) static Element[]
toElementArray
(JavaScriptObject array) static Float
toFloat
(float value) static Integer
toInteger
(int value) static Long
toLong
(double value)
-
Method Details
-
getClassName
Returns the javascript class name.- Returns:
-
isScClassInstance
Returns whether the supplied JavaScriptObject is a SmartClient class instance.- Parameters:
the
- object to evaluate- Returns:
- whether object is an instance
-
isScClassObject
Returns whether the supplied JavaScriptObject is a SmartClient class (a Class object itself, rather than an instance of a class).- Parameters:
the
- object to evaluate- Returns:
- whether object is a Class object
-
eval
Evaluate the passed string as Javascript- Parameters:
jsFrag
- the string to evaluate- Returns:
- the JavaScriptObject upon evaluation
-
isJSO
-
doubleValue
-
getAttribute
-
setAttribute
-
getAttributeAsJavaScriptObject
-
getAttributeAsJavaScriptObjectArray
public static JavaScriptObject[] getAttributeAsJavaScriptObjectArray(JavaScriptObject elem, String attr) -
toArray
-
isArray
-
toElementArray
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
Set the value of attribute "attr" in object "elem" to the Object "value"This method converts the value passed in to an equivalent object in JavaScript before storing on the underlying data object - see
JavaToJavaScriptConversion
for details of the conversions that take place.
Developers can usesetObjectAttribute(JavaScriptObject, String, Object)
to store Java objects without converting to JavaScript.- Parameters:
elem
- the JavaScriptObject on which to set the attributeattr
- the attribute namevalue
- the attribute value.
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setNullAttribute
-
deleteAttribute
-
deleteAttributeIfExists
-
setAttribute
-
setAttribute
-
setAttribute
-
setAttribute
-
setObjectAttribute
-
getAttributeAsElement
-
getAttributeAsInt
-
getAttributeAsDouble
-
getAttributeAsDate
-
getAttributeAsFloat
-
getAttributeAsIntArray
-
getAttributeAsDoubleArray
-
getAttributeAsStringArray
-
getJavaScriptObjectArraySize
-
getIntValueFromJavaScriptObjectArray
-
getDoubleValueFromJavaScriptObjectArray
-
getStringValueFromJavaScriptObjectArray
-
getValueFromJavaScriptObjectArray
-
getCellArray
-
convertToCellArray
-
getAttributeAsBoolean
Returns attribute value set as a Boolean. For convenience in checking boolean properties,getAttributeAsBoolean
will return Booleanfalse
if the attribute value isnull
or not a Boolean. Use the three parameter variant of this APIgetAttributeAsBoolean(JavaScriptObject, String, boolean)
if you wantnull
returned fornull
attribute values.- Parameters:
elem
- the JavaScriptObject containing the propertyattr
- the property name- Returns:
- the property value
-
getAttributeAsBoolean
Returns attribute value set as a Boolean. If the attribute value isnull
or not a Boolean, the return value depends uponallowNull
. IfallowNull
is true,null
will be returned; otherwise Booleanfalse
will be returned. For a simpler approach that never returnsnull
, use the two parameter variant of this APIgetAttributeAsBoolean(JavaScriptObject, String)
.- Parameters:
elem
- the JavaScriptObject containing the propertyattr
- the property nameallowNull
- whether to permit anull
return value- Returns:
- the property value
-
getAttributeAsObject
-
getAttributeAsMap
Returns attribute "attr" of JavaScriptObject "elem", converted to a Map following the rules described in theJS -> Java conversion article
- Parameters:
elem
- JavaScriptObject containing the attributeattr
- The attribute name- Returns:
- The attribute converted to a Java Map
-
listToArray
-
arrayConvert
-
arrayConvert
-
arrayLength
-
arrayGetObject
-
arraySet
-
arraySet
-
getElementValueFromJavaScriptObjectArray
This is used to access Element array as JavaScriptObject -
createObject
-
convertToJavaScriptArray
-
convertToJavaScriptArray
-
convertToJavaScriptArray
-
convertToJavaScriptArray
-
convertToJavaScriptArray
-
convertToJavaScriptArray
-
convertToJavaScriptArray
-
convertToJavaScriptArray
-
convertToJava
Convert a JavaScriptObject to the appropriate type of Java Object, following the rules described in theJS -> Java conversion article
- Parameters:
object
- JavaScriptObject to convertlistAsArray
- Should arrays be converted to Object[] or List- Returns:
- converted Java object. May be a Map, a List, an Object[], a JavaScriptObject, a Canvas or a FormItem, depending on the underlying JavaScript type
-
convertToJava
Convert a JavaScriptObject to the appropriate type of Java Object, following the rules described in theJS -> Java conversion article
. Any arrays encountered during conversion will be converted to JavaArrayList
s- Parameters:
object
- JavaScriptObject to convert- Returns:
- converted Java object. May be a Map, a List, an Object[], a JavaScriptObject, a Canvas or a FormItem, depending on the underlying JavaScript type
-
convertToMap
Convert a JavaScript object containing key:value pairs to a Java Map, following the rules described in theJS -> Java conversion article
- Parameters:
jsObj
- the JavaScript object to convertlistAsArray
- Should arrays be converted to Object[] or List- Returns:
- the map
- Throws:
IllegalArgumentException
- if unable to convert the passed JavaScript object to a map
-
convertToMap
Convert a JavaScript object containing key:value pairs to a Java Map, following the rules described in theJS -> Java conversion article
. Any arrays encountered during the conversion process will be converted to JavaArrayList
s- Parameters:
jsObj
- the JavaScript object to convert- Returns:
- the map
- Throws:
IllegalArgumentException
- if unable to convert the passed JavaScript object to a map
-
convertToArray
Convert a JavaScript object to an Object[], following the rules described in theJS -> Java conversion article
. If the JavaScript object is not an array in Javascript, a new array will be created containing the converted object as the only entry.- Parameters:
object
- the JavaScript object to convert- Returns:
- the JavaScript object converted to a Java Object array
-
convertToList
Convert a JavaScript object to a List, following the rules described in theJS -> Java conversion article
. If the JavaScript object is not an array in JavaScript, a new List will be created containing the converted object as the only entry.- Parameters:
object
- the JavaScript object to convert- Returns:
- the JavaScript object converted to a Java List
-
convertToJavaScriptDate
-
convertToJavaDate
-
convertToString
-
isJavaDate
- Parameters:
obj
- the object- Returns:
- true if object is a Java Date
-
isJavaNumber
- Parameters:
obj
- the object- Returns:
- true if object is a Java Number
-
isJavaInteger
- Parameters:
obj
- the object- Returns:
- true if object is a Java Integer
-
isJavaFloat
- Parameters:
obj
- the object- Returns:
- true if object is a Java Float
-
isJavaDouble
- Parameters:
obj
- the object- Returns:
- true if object is a Java Double
-
isJavaString
- Parameters:
obj
- the object- Returns:
- true if object is a Java String
-
isJavaBoolean
- Parameters:
obj
- the object- Returns:
- true if object is a Java Integer
-
isJavaList
-
isJavaMap
-
isJavaArray
- Parameters:
obj
- the object- Returns:
- true if object is a Java Array
-
convertToJsArray
-
convertToJavaScriptArray
Converts the parameter Object array to an equivalent Javascript array - seeJavaToJavaScriptConversion
for details of the conversions that take place.- Parameters:
array
- the Java Object array to convert
-
convertToJavaScriptArray
-
throwUnconvertibleObjectException
-
toInteger
-
toLong
-
toFloat
-
toDouble
-
toDate
Converts a time to a JavaDate
object.Note: If needing to convert a JavaScript object, it is preferable to use
convertToJavaDate(JavaScriptObject)
instead because that function is able to convert toLogicalDate
andLogicalTime
instances as needed.- Parameters:
millis
- number of milliseconds since January 1, 1970, 00:00:00 GMT.- Returns:
- a new
Date
representing the given time.
-
toDateJS
-
getJSLogicalDate
-
getJSLogicalDate
-
getJSLogicalTime
-
getJSLogicalTime
-
toBoolean
-
createJavaScriptArray
-
setArrayValue
-
setArrayValue
-
setArrayValue
-
setArrayValue
-
setArrayValue
-
setArrayValue
-
setArrayValue
-
setArrayValue
-
getArrayValue
-
getJSOArrayValue
-
getObjectArrayValue
-
getBooleanArrayValue
-
getIntArrayValue
-
getfloatArrayValue
-
getdoubleArrayValue
-
getIntegerArrayValue
-
getFloatArrayValue
-
getDoubleArrayValue
-
getDateArrayValue
-
getArrayLength
-
convertToJavaBooleanArray
-
convertToJavaIntArray
-
convertToJavaInterArray
Deprecated.deprecated in favor ofconvertToJavaIntegerArray(com.google.gwt.core.client.JavaScriptObject)
-
convertToJavaIntegerArray
-
convertToJavaStringArray
-
convertToJavaFloatArray
-
convertToJavaDoubleArray
-
convertToJavaDateArray
-
convertToJavaObjectArray
-
convertToJavaRefDataClassArray
-
apply
-
setAttribute
Sets attribute "attr" on Javascript object "jsObj" to the JavaScript equivalent of "valueMap". SeeJavaToJavaScriptConversion
for details of the conversions that take place.- Parameters:
jsObj
- the JavaScript object on which to set the attributeattr
- the name of the attribute to setvalueMap
- the Java Map to convert and apply as the attribute value
-
convertMapToJavascriptObject
Converts the parameter Map to an equivalent Javascript object - seeJavaToJavaScriptConversion
for details of the conversions that take place.- Parameters:
array
- the Java Map to convert
-
convertMapToJavascriptObject
-
getProperties
-
getPropertiesAsString
-
addProperties
public static JavaScriptObject addProperties(JavaScriptObject destination, JavaScriptObject propertiesObject) Adds all properties and methods from the propertiesObject to the destination object.- Parameters:
destination
- the destination objectpropertiesObject
- the propertiesObject
-
cleanProperties
Removes non-transferable properties from the supplied object (e.g. widget ID), performing a copy first if requested.- Parameters:
properties
- the supplied object to cleancopyProperties
- whether to copy the object first- Returns:
- the cleaned properties object
-
callMethod
Invoke a method on some JavaScript object, passing in the specified array of parameters.This method converts the specified parameters to a equivalent objects in JavaScript before calling the method in JavaScript scope, and will convert any return value to Java before returning it - see
JavaToJavaScriptConversion
for details of the conversions that take place.
If the invoked method has no return value, this method will return null.- Parameters:
target
-methodName
-arguments
-- Returns:
-
convertToJavaIntegerArray(com.google.gwt.core.client.JavaScriptObject)