Package com.vaadin.client
Class WidgetUtil
java.lang.Object
com.vaadin.client.WidgetUtil
Utility methods which are related to client side code only.
- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcrazyJsCast(Object value) Anything in, anything out.static <T extends com.google.gwt.core.client.JavaScriptObject>
TcrazyJsoCast(Object value) Anything in, JSO out.static elemental.json.JsonObjectCreates a newJsonObjectwith the JavaScript prototype.static elemental.json.JsonObjectCreates a newJsonObjectwithout any JavaScript prototype at all.static voiddeleteJsProperty(Object object, String name) Removes a JavaScript property from an object.static booleanChecks whether the objects are equal either as Java objects (considering types and JavaObject.equals(Object)method) or as JS values.static booleanequalsInJS(Object obj1, Object obj2) Checks whether the objects are equal as JS values.static StringgetAbsoluteUrl(String url) Resolve a relative URL to an absolute URL based on the current document's location.static ObjectgetJsProperty(Object object, String name) Retrieves the value of a JavaScript property.static String[]Gets all JavaScript property names of the given object.static booleanhasJsProperty(Object object, String name) Checks whether the provided object has or inherits a JavaScript property with the given name.static booleanhasOwnJsProperty(Object object, String name) Checks whether the provided object itself has a JavaScript property with the given name.static booleanisAbsoluteUrl(String url) Detects if an URL is absolute.static booleanGets the boolean value of the provided value based on JavaScript semantics.static booleanisUndefined(Object property) Checks if the given value is explicitly undefined.static voidRedirects the browser to the given url or refreshes the page if url is nullstatic voidrefresh()Refreshes the browser.static voidsetJsProperty(Object object, String name, Object value) Assigns a value as JavaScript property of an object.static Stringstringify(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 StringtoPrettyJson(elemental.json.JsonValue json) Converts a JSON value to a formatted string.static voidupdateAttribute(elemental.dom.Element element, String attribute, String value) Updates theattributevalue for theelementto the givenvalue.
-
Constructor Details
-
WidgetUtil
public WidgetUtil()
-
-
Method Details
-
refresh
public static void refresh()Refreshes the browser. -
redirect
Redirects the browser to the given url or refreshes the page if url is null- Parameters:
url- The url to redirect to or null to refresh
-
getAbsoluteUrl
Resolve a relative URL to an absolute URL based on the current document's location.- Parameters:
url- a string with the relative URL to resolve- Returns:
- the corresponding absolute URL as a string
-
isAbsoluteUrl
Detects if an URL is absolute. URLs wihtout schema but starting with double slashes (e.g. //myhost/path} are considered absolute.- Parameters:
url- a string with the URL to check- Returns:
- true if the url is absolute, otherwise false.
-
crazyJsCast
Anything in, anything out. It's JavaScript after all. This method just makes the Java compiler accept the fact.- Type Parameters:
T- the object type- Parameters:
value- anything- Returns:
- the same stuff
-
crazyJsoCast
Anything in, JSO out. It's JavaScript after all. This method just makes the Java compiler accept the fact. The regular crazy cast doesn't work for JSOs since the generics still makes the compiler insert a JSO check.- Type Parameters:
T- the object type- Parameters:
value- anything- Returns:
- the same stuff
-
toPrettyJson
Converts a JSON value to a formatted string.- Parameters:
json- the JSON value to stringify- Returns:
- the JSON string
-
updateAttribute
Updates theattributevalue for theelementto the givenvalue.If
valueisnullthenattributeis removed, otherwisevalueis set as its value.- Parameters:
element- the DOM element owning attributeattribute- the attribute to updatevalue- the value to update
-
setJsProperty
Assigns a value as JavaScript property of an object.- Parameters:
object- the target objectname- the property namevalue- the property value
-
getJsProperty
Retrieves the value of a JavaScript property.- Parameters:
object- the target objectname- the property name- Returns:
- the value
-
hasOwnJsProperty
Checks whether the provided object itself has a JavaScript property with the given name. Inherited properties are not taken into account.- Parameters:
object- the target objectname- the name of the property- Returns:
trueif the object itself has the named property;falseif it doesn't have the property of if the property is inherited- See Also:
-
hasJsProperty
Checks whether the provided object has or inherits a JavaScript property with the given name.- Parameters:
object- the target objectname- the name of the property- Returns:
trueif the object itself has or inherits the named property;falseotherwise- See Also:
-
isUndefined
Checks if the given value is explicitly undefined.nullvalues returnsfalse.- Parameters:
property- the value to be verified- Returns:
trueis the value is explicitly undefined,falseotherwise
-
deleteJsProperty
Removes a JavaScript property from an object.- Parameters:
object- the object from which to remove the propertyname- the name of the property to remove
-
createJsonObjectWithoutPrototype
public static elemental.json.JsonObject createJsonObjectWithoutPrototype()Creates a newJsonObjectwithout any JavaScript prototype at all. Not having any prototype is only relevant for objects that are displayed through the browser console.- Returns:
- a new json object
-
createJsonObject
public static elemental.json.JsonObject createJsonObject()Creates a newJsonObjectwith the JavaScript prototype.- Returns:
- a new json object
-
isTrueish
Gets the boolean value of the provided value based on JavaScript semantics.- Parameters:
value- the value to check for truthness- Returns:
trueif the provided value is trueish according to JavaScript semantics, otherwisefalse
-
getKeys
Gets all JavaScript property names of the given object. This directly callsObject.keys.- Parameters:
value- the value to get keys for- Returns:
- an array of key names
-
stringify
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.- Parameters:
payload- JsonObject to stringify- Returns:
- json string of given object
-
equals
Checks whether the objects are equal either as Java objects (considering types and JavaObject.equals(Object)method) or as JS values.- Parameters:
obj1- an objectobj2- an object to be compared withafor deep equality- Returns:
trueif the arguments are equal to each other andfalseotherwise- See Also:
-
equalsInJS
Checks whether the objects are equal as JS values.This check ignores object types and checks the values via JS
==. E.g. it means that an empty string equals to0.- Parameters:
obj1- an objectobj2- an object to be compared withafor deep equality- Returns:
trueif the arguments are equal via JS==to each other andfalseotherwise
-