Class RemoteCommandUtils
java.lang.Object
de.xima.fc.gui.common.utils.RemoteCommandUtils
Helper methods for
<p:remoteCommand>, such as reading parameters and returning a value.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidSets the success return value tofalseand also add the error message as a return parameter.static voidaddReturnValue(String paramName, boolean value) Adds a return value for the remote command with the given parameter name.static voidaddReturnValue(String paramName, int value) Adds a return value for the remote command with the given parameter name.static voidaddReturnValue(String paramName, long value) Adds a return value for the remote command with the given parameter name.static voidaddReturnValue(String paramName, Object value) Adds a return value for the remote command with the given parameter name.static voidaddReturnValueJson(String paramName, Object value) Adds a return value for the remote command with the given parameter name.static voidSets the success return parameter totrue.static voiddelayResponse(String delayId) Can be used when the response to a remote command cannot be computed synchronously.static <T> TGets the value of the parameter with the given name and parses it using the given parser.static booleangetBoolean(String paramName) getBooleanOptional(String paramName) static <T extends Enum<T>>
Tstatic OptionalIntstatic intstatic <T> List<T> getJsonArray(String paramName, Class<T> clazz) static com.alibaba.fastjson.JSONObjectgetJsonObject(String paramName) static com.alibaba.fastjson.JSONObjectgetJsonObject(String paramName, com.alibaba.fastjson.JSONObject defaultValue) static <T> TgetJsonObject(String paramName, Class<T> clazz) static <T> TgetJsonObject(String paramName, Class<T> clazz, T defaultValue) static List<com.alibaba.fastjson.JSONObject> getListOfJsonObjects(String paramName) static <T> List<T> getListOfJsonObjects(String paramName, Class<T> clazz) getListOfLongs(String paramName) getListOfStrings(String paramName) static Localestatic Localestatic OptionalLongstatic longstatic Optional<com.vdurmont.semver4j.Semver> static com.vdurmont.semver4j.SemvergetSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type, com.vdurmont.semver4j.Semver defaultValue) getSetOfLongs(String paramName) getSetOfStrings(String paramName) static Stringstatic StringgetStringOptional(String paramName) static voidresolveDelayed(String delayId) Marks the response as the result for the given delay ID.
-
Method Details
-
addError
Sets the success return value tofalseand also add the error message as a return parameter.- Parameters:
e- Exception that occurred.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue.- Parameters:
paramName- Name of the parameter, can be used on the client to access the parameter.value- Boolean value to be returned.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue.- Parameters:
paramName- Name of the parameter, can be used on the client to access the parameter.value- Integer value to be returned.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue.- Parameters:
paramName- Name of the parameter, can be used on the client to access the parameter.value- Long value to be returned.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue.- Parameters:
paramName- Name of the parameter, can be used on the client to access the parameter.value- Value to be returned. This value is stringified.
-
addReturnValueJson
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue. The value is converted to a JSON string.- Parameters:
paramName- Name of the parameter, can be used on the client to access the parameter.value- Value to be returned. This value is stringified.
-
addSuccess
public static void addSuccess()Sets the success return parameter totrue. -
delayResponse
Can be used when the response to a remote command cannot be computed synchronously. Must be given a delay ID that should be passed toresolveDelayed(String).- Parameters:
delayId- The delay ID that must be used to resolve the delayed remote command. Must be passed toresolveDelayed(String)or the client-side promise will never resolve
-
getAs
Gets the value of the parameter with the given name and parses it using the given parser.- Type Parameters:
T- Type to parse the parameter value to.- Parameters:
paramName- Name of the parameter to read.parser- Function to parse the parameter value.- Returns:
- The parsed value of the parameter, or
nullif the parameter is not present or its value cannot be parsed.
-
getBoolean
- Parameters:
paramName- Name of the parameter to read.- Returns:
- The boolean value of the parameter,
falsewhen the parameter is not present.
-
getBooleanOptional
-
getEnum
- Type Parameters:
T- Type of the enum.- Parameters:
paramName- Name of the parameter to read.enumType- Type of the enum.- Returns:
- The enum value of the parameter, or
nullwhen the parameter is not present or no such enum constant exists.
-
getInt
- Parameters:
paramName- Name of the parameter to read.- Returns:
- The int value of the parameter, empty if no such parameter exists or it its not a valid int.
-
getInt
- Parameters:
paramName- Name of the parameter to read.defaultValue- Default value used when parameter does not exist or is not a valid int.- Returns:
- The int value of the parameter, default value if no such parameter exists or it its not a valid int.
-
getJsonArray
- Type Parameters:
T- Type to create from the JSON.- Parameters:
paramName- Name of the parameter to read.clazz- Type to create from the JSON.- Returns:
- The value of the parameter parsed as a deserialized list, empty list if no such parameter exists or it is invalid.
-
getJsonObject
- Parameters:
paramName- Name of the parameter to read.- Returns:
- The value of the parameter parsed as a JSON object, empty object if no such parameter exists or it is invalid.
-
getJsonObject
- Type Parameters:
T- Type to create from the JSON.- Parameters:
paramName- Name of the parameter to read.clazz- Type to create from the JSON.- Returns:
- The value of the parameter parsed as a deserialized object, null if no such parameter exists or it is invalid.
-
getJsonObject
- Type Parameters:
T- Type to create from the JSON.- Parameters:
paramName- Name of the parameter to read.clazz- Type to create from the JSON.defaultValue- Default value to return when the parameter could not be read.- Returns:
- The value of the parameter parsed as a deserialized object, default value if no such parameter exists or it is invalid.
-
getJsonObject
public static com.alibaba.fastjson.JSONObject getJsonObject(String paramName, com.alibaba.fastjson.JSONObject defaultValue) - Parameters:
paramName- Name of the parameter to read.defaultValue- Default value used when parameter does not exist or is invalid.- Returns:
- The value of the parameter parsed as a JSON object, default value if no such parameter exists or it is invalid.
-
getListOfJsonObjects
-
getListOfJsonObjects
- Type Parameters:
T- Type to create from the JSON.- Parameters:
paramName- Name of the parameter to read. Nevernull, only empty.clazz- Type to create from the JSON.- Returns:
- A list of all values for the given parameter, parsed as a JSON object of the given class.
-
getListOfLongs
-
getListOfStrings
-
getLocale
-
getLocale
-
getLong
- Parameters:
paramName- Name of the parameter to read.- Returns:
- The long value of the parameter, empty if no such parameter exists or it its not a valid long.
-
getLong
- Parameters:
paramName- Name of the parameter to read.defaultValue- Default value used when parameter does not exist or is not a valid long.- Returns:
- The long value of the parameter, default value if no such parameter exists or it its not a valid long.
-
getSemver
public static Optional<com.vdurmont.semver4j.Semver> getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type) - Parameters:
paramName- Name of the parameter to read.type- Semver type to use for parsing.- Returns:
- The boolean value of the parameter,
falsewhen the parameter is not present.
-
getSemver
public static com.vdurmont.semver4j.Semver getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type, com.vdurmont.semver4j.Semver defaultValue) - Parameters:
paramName- Name of the parameter to read.type- Semver type to use for parsing.defaultValue- Default used when the value cannot be parsed as a semver.- Returns:
- The boolean value of the parameter,
falsewhen the parameter is not present.
-
getSetOfStrings
-
getSetOfLongs
-
getString
-
getString
-
getStringOptional
-
resolveDelayed
Marks the response as the result for the given delay ID. Must be called after all other calls that add values, such asaddSuccess(),addError(Throwable),addReturnValue(String, boolean)etc.- Parameters:
delayId- The delay ID that was passed todelayResponse(String).
-