public class WidgetUtil extends Object
| Constructor and Description |
|---|
WidgetUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
crazyJsCast(Object value)
Anything in, anything out.
|
static <T extends com.google.gwt.core.client.JavaScriptObject> |
crazyJsoCast(Object value)
Anything in, JSO out.
|
static elemental.json.JsonObject |
createJsonObject()
Creates a new
JsonObject with the JavaScript prototype. |
static elemental.json.JsonObject |
createJsonObjectWithoutPrototype()
Creates a new
JsonObject without any JavaScript prototype at all. |
static void |
deleteJsProperty(Object object,
String name)
Removes a JavaScript property from an object.
|
static boolean |
equals(Object obj1,
Object obj2)
Checks whether the objects are equal either as Java objects (considering
types and Java
Object.equals(Object) method) or as JS values. |
static boolean |
equalsInJS(Object obj1,
Object obj2)
Checks whether the objects are equal as JS values.
|
static String |
getAbsoluteUrl(String url)
Resolve a relative URL to an absolute URL based on the current document's
location.
|
static Object |
getJsProperty(Object object,
String name)
Retrieves the value of a JavaScript property.
|
static String[] |
getKeys(Object value)
Gets all JavaScript property names of the given object.
|
static boolean |
hasJsProperty(Object object,
String name)
Checks whether the provided object has or inherits a JavaScript property
with the given name.
|
static boolean |
hasOwnJsProperty(Object object,
String name)
Checks whether the provided object itself has a JavaScript property with
the given name.
|
static boolean |
isTrueish(Object value)
Gets the boolean value of the provided value based on JavaScript
semantics.
|
static boolean |
isUndefined(Object property)
Checks if the given value is explicitly undefined.
|
static void |
redirect(String url)
Redirects the browser to the given url or refreshes the page if url is
null
|
static void |
refresh()
Refreshes the browser.
|
static void |
setJsProperty(Object object,
String name,
Object value)
Assigns a value as JavaScript property of an object.
|
static String |
stringify(elemental.json.JsonObject payload)
When serializing the JsonObject we check the values for dom nodes and
throw and exception if one is found as they should not be synced and may
create cyclic dependencies.
|
static String |
toPrettyJson(elemental.json.JsonValue json)
Converts a JSON value to a formatted string.
|
static void |
updateAttribute(elemental.dom.Element element,
String attribute,
String value)
Updates the
attribute value for the element to the given
value. |
public static void refresh()
public static void redirect(String url)
url - The url to redirect to or null to refreshpublic static String getAbsoluteUrl(String url)
url - a string with the relative URL to resolvepublic static <T> T crazyJsCast(Object value)
T - the object typevalue - anythingpublic static <T extends com.google.gwt.core.client.JavaScriptObject> T crazyJsoCast(Object value)
T - the object typevalue - anythingpublic static String toPrettyJson(elemental.json.JsonValue json)
json - the JSON value to stringifypublic static void updateAttribute(elemental.dom.Element element,
String attribute,
String value)
attribute value for the element to the given
value.
If value is null then attribute is removed,
otherwise value is set as its value.
element - the DOM element owning attributeattribute - the attribute to updatevalue - the value to updatepublic static void setJsProperty(Object object, String name, Object value)
object - the target objectname - the property namevalue - the property valuepublic static Object getJsProperty(Object object, String name)
object - the target objectname - the property namepublic static boolean hasOwnJsProperty(Object object, String name)
object - the target objectname - the name of the propertytrue if the object itself has the named property;
false if it doesn't have the property of if the
property is inheritedhasJsProperty(Object, String)public static boolean hasJsProperty(Object object, String name)
object - the target objectname - the name of the propertytrue if the object itself has or inherits the named
property; false otherwisehasOwnJsProperty(Object, String)public static boolean isUndefined(Object property)
null
values returns false.property - the value to be verifiedtrue is the value is explicitly undefined,
false otherwisepublic static void deleteJsProperty(Object object, String name)
object - the object from which to remove the propertyname - the name of the property to removepublic static elemental.json.JsonObject createJsonObjectWithoutPrototype()
JsonObject without any JavaScript prototype at all.
Not having any prototype is only relevant for objects that are displayed
through the browser console.public static elemental.json.JsonObject createJsonObject()
JsonObject with the JavaScript prototype.public static boolean isTrueish(Object value)
value - the value to check for truthnesstrue if the provided value is trueish according to
JavaScript semantics, otherwise falsepublic static String[] getKeys(Object value)
Object.keys.value - the value to get keys forpublic static String stringify(elemental.json.JsonObject payload)
payload - JsonObject to stringifypublic static boolean equals(Object obj1, Object obj2)
Object.equals(Object) method) or as JS values.obj1 - an objectobj2 - an object to be compared with a for deep equalitytrue if the arguments are equal to each other and
false otherwiseequalsInJS(Object, Object)public static boolean equalsInJS(Object obj1, Object obj2)
This check ignores object types and checks the values via JS ==.
E.g. it means that an empty string equals to 0.
obj1 - an objectobj2 - an object to be compared with a for deep equalitytrue if the arguments are equal via JS == to each
other and false otherwiseCopyright © 2000–2021 Vaadin Ltd. All rights reserved.