Package org.opencms.gwt.client.util
Class CmsJsUtil
java.lang.Object
org.opencms.gwt.client.util.CmsJsUtil
A class containing generic Javascript utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcallNamedFunctionWithString(String name, String param) Calls a named global function (i.e.static voidcallNamedFunctionWithString2(String name, String param1, String param2) Calls a named global function (i.e.static voidcallWithString(com.google.gwt.core.client.JavaScriptObject func, String param) Calls a JS function with a string parameter.static voidCloses the browser window.static com.google.gwt.user.client.CommandconvertCallbackToCommand(com.google.gwt.core.client.JavaScriptObject func) Creates a Command object which calls the given native JS function.static voidfillStringMapFromJsObject(com.google.gwt.core.client.JavaScriptObject jso, Map<String, String> map) Iterates over attributes of a Javascript object and copies them to a string map.static voidforceLoadUri(String uri) Opens the given URI in the current browser window, ensuring that a request to the server is triggered.static com.google.gwt.core.client.JavaScriptObjectgetAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads an attribute from a Javascript object.static StringgetAttributeString(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads a string-valued attribute from a Javascript object.static StringgetLocalStorage(String key) static com.google.gwt.core.client.JavaScriptObjectGets the current window as a Javascript object.static com.google.gwt.core.client.JsArrayStringnewArray()Creates an empty Javascript string array.static com.google.gwt.core.client.JavaScriptObjectCreates a JavaScript object from a JSON string.static voidsetAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr, com.google.gwt.core.client.JavaScriptObject newValue) Sets an attribute of the given Javascript object to a new value.static com.google.gwt.core.client.JavaScriptObjectstatic com.google.gwt.user.client.rpc.AsyncCallback<String> wrapCallback(com.google.gwt.core.client.JavaScriptObject func) Wraps a native JavaScript callback taking a string argument into an AsyncCallback so that it can easily be called from GWT Java code.
-
Method Details
-
callNamedFunctionWithString
Calls a named global function (i.e. a function-valued attribute of window) with a string argument.- Parameters:
name- the function nameparam- the function parameter
-
callNamedFunctionWithString2
Calls a named global function (i.e. a function-valued attribute of window) with a string argument.- Parameters:
name- the function nameparam1- a function parameterparam2- a function parameter
-
callWithString
Calls a JS function with a string parameter.- Parameters:
func- the Javascript functionparam- the string parameter
-
closeWindow
Closes the browser window. -
convertCallbackToCommand
public static com.google.gwt.user.client.Command convertCallbackToCommand(com.google.gwt.core.client.JavaScriptObject func) Creates a Command object which calls the given native JS function.- Parameters:
func- a Javascript function- Returns:
- a Command object which calls the native function
-
fillStringMapFromJsObject
public static void fillStringMapFromJsObject(com.google.gwt.core.client.JavaScriptObject jso, Map<String, String> map) Iterates over attributes of a Javascript object and copies them to a string map.Converts all values to strings.
- Parameters:
jso- the Javascript objectmap- the map to fill
-
forceLoadUri
Opens the given URI in the current browser window, ensuring that a request to the server is triggered.- Parameters:
uri- the URI to open
-
getAttribute
public static com.google.gwt.core.client.JavaScriptObject getAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads an attribute from a Javascript object.- Parameters:
jso- the Javascript objectattr- the name of the attribute- Returns:
- the value of the attribute
-
getAttributeString
public static String getAttributeString(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads a string-valued attribute from a Javascript object.- Parameters:
jso- the Javascript objectattr- the name of the attribute- Returns:
- the value of the attribute
-
getLocalStorage
-
getWindow
Gets the current window as a Javascript object.- Returns:
- the current window
-
newArray
Creates an empty Javascript string array.- Returns:
- the new array
-
parseJSON
Creates a JavaScript object from a JSON string.- Parameters:
json- the JSON string- Returns:
- the JavaScript object parsed from the JSON string
-
setAttribute
public static void setAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr, com.google.gwt.core.client.JavaScriptObject newValue) Sets an attribute of the given Javascript object to a new value.- Parameters:
jso- the object to modifyattr- the attribute to setnewValue- the new attribute value
-
toJavaScriptObject
-
wrapCallback
public static com.google.gwt.user.client.rpc.AsyncCallback<String> wrapCallback(com.google.gwt.core.client.JavaScriptObject func) Wraps a native JavaScript callback taking a string argument into an AsyncCallback so that it can easily be called from GWT Java code.- Parameters:
func- the function to wrap- Returns:
- the AsyncCallback wrapper
-