Class ClientUtil
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
A configuration object that holds all the settings to be used for presenting the requested dialog on the clientside -
Method Summary
Modifier and TypeMethodDescriptionstatic Pair<String,
JSONObject> Get a JSONObject from an ActivityInstance in the context of a worklist node.static JSONObject
getAsJSON
(String wlNodeId, ActivityInstance ai) Get a JSONObject from an ActivityInstance in the context of a worklist node.static JSONObject
getAsJSON
(String nodeId, HttpServletRequest req, String objectId) Builds aJSONObject
representation for an object as it's expected by the client side store.static JSONObject
Builds aJSONObject
from aMap
of data for a table row.static JSONObject
getAsJSON
(HttpServletRequest req, Persistent object) Builds aJSONObject
representation for an object as it's expected by the client side store.static JSONObject
Get a JSONObject suitable for sending the threads own changes back to the Gui.static JSONObject
getChangesAsJSON
(boolean avoidAutoNotification) Get a JSONObject suitable for sending the threads own changes back to the Gui.static JSONObject
getChangesAsJSON
(String guiId) Get a JSONObject suitable for sending the threads own changes back to the Gui.static JSONObject
getChangesAsJSON
(String guiId, boolean avoidAutoNotification) Get a JSONObject suitable for sending the threads own changes back to the Gui.static JSONObject
Get a JSONObject suitable for sending the threads own changes back to the Gui.static JSONObject
getChangesAsJSON
(String guiId, Set<Pair<Long, Long>> additionalChangeSet, boolean avoidAutoNotification) Get a JSONObject suitable for sending the threads own changes back to the Gui.static String
getGuiId()
Get the id of the current gui.static String
Get the id of the current gui from the HttpServletRequestTransform a collection of ActivityInstances to a suitable structure forgetChangesAsJSON(String, Set)
.static String
userInput
(String parameterName, Consumer<ClientUtil.DialogConfiguration> builder) Can be used to request input from the user during interactive transactions.static String
userInput
(String parameterName, Supplier<ClientUtil.DialogConfiguration> builder) Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Details
-
getGuiId
Get the id of the current gui.- Returns:
- the id of the current gui associated with the session of this threads HttpThread or the ThreadContext Gui attribute or null if there is neither a HttpSession nor a Gui attribute in the ThreadContext available.
-
getGuiId
Get the id of the current gui from the HttpServletRequest- Parameters:
req
- the request- Returns:
- the id of the current gui associated with the session of the request or the ThreadContext Gui attribute or null if there is neither a HttpSession nor a Gui attribute in the ThreadContext available.
-
getChangesAsJSON
Get a JSONObject suitable for sending the threads own changes back to the Gui. The guiid used is the one returned bygetGuiId()
.- Returns:
- a JSONObject
- See Also:
-
getChangesAsJSON
Get a JSONObject suitable for sending the threads own changes back to the Gui. The guiid used is the one returned bygetGuiId()
.- Parameters:
avoidAutoNotification
- if true, the changes will not be send back to the originating client session via notification.- Returns:
- a JSONObject
- See Also:
-
getChangesAsJSON
Get a JSONObject suitable for sending the threads own changes back to the Gui.- Parameters:
guiId
- the id of the XMLGui to use- Returns:
- a JSONObject
- See Also:
-
getChangesAsJSON
Get a JSONObject suitable for sending the threads own changes back to the Gui.- Parameters:
guiId
- the id of the XMLGui to useavoidAutoNotification
- if true, the changes will not be send back to the originating client session via notification.- Returns:
- a JSONObject
- See Also:
-
toChangeSet
Transform a collection of ActivityInstances to a suitable structure forgetChangesAsJSON(String, Set)
.- Parameters:
ais
- the collection of ActivityInstances- Returns:
- the change set.
-
getChangesAsJSON
Get a JSONObject suitable for sending the threads own changes back to the Gui.Beware: this call commits the actions.
- Parameters:
guiId
- the id of the XMLGui to use; can also be nodeId, then the guiId prefix will be extracted.additionalChangeSet
- additional information about changes to activityinstances that could not be automatically detected by the system. Can be null.- Returns:
- a JSONObject with entries for pending, deleted and changed worklist items.
- See Also:
-
getChangesAsJSON
public static JSONObject getChangesAsJSON(String guiId, Set<Pair<Long, Long>> additionalChangeSet, boolean avoidAutoNotification) Get a JSONObject suitable for sending the threads own changes back to the Gui.Beware: this call commits the actions.
According the
additionalChangeSet
parameter: sometimes the activityinstances do not change, but nevertheless they may end up in different worklists (e.g. movement), since there are no updates associated with this activityinstances, there are no detectable storage events for this activityinstances. TheadditionalChangeSet
parameter can be used to inform this method about such changes. It is a set of pairs of oids and transactionids of such activityinstances that did not change in terms of the database but in terms of gui representation (see:toChangeSet(Collection)
).N.B.Changes specified via
additionalChangeSet
will only be reflected in the result of this function and not in notifications for other sessions. If other sessions should be notified about such undetectable changes too, useWfEngine.propagateChange(ActivityInstance)
before calling this function.- Parameters:
guiId
- the id of the XMLGui to use; can also be nodeId, then the guiId prefix will be extracted.additionalChangeSet
- additional information about changes to activityinstances that could not be automatically detected by the system. Can be null.avoidAutoNotification
- if true, the changes will not be send back to the originating client session via notification. In this case the it is the responsibility of the caller to send the changes back itself.- Returns:
- a JSONObject with entries for pending, deleted and changed worklist items. The JSONObject is also written to the log if the log level for com.groiss.smartclient.Util is set at least to DEBUG
-
getAsJSON
Get a JSONObject from an ActivityInstance in the context of a worklist node. The worklist node is determined from the gui of the current session. The worklists are consulted one after the other just with the ActivityInstance. If a worklist returns something, this worklist is used, no other worklists are consulted. If no worklist returns anything, null is returned.- Parameters:
ai
- the ActivityInstance- Returns:
- a Pair the first element is the id of the worklist node, the second element is a JSONObject representation of the ActivityInstance according to the worklist node The JSONObject is also written to the log if the log level for com.groiss.smartclient.Util is set at least to DEBUG
-
getAsJSON
Get a JSONObject from an ActivityInstance in the context of a worklist node.- Parameters:
wlNodeId
- the id of the worklist node in the the XMLGui to use. Must be prefixed by a gui id (e.g. standard.wl).ai
- the ActivityInstance- Returns:
- a JSONObject representation of the ActivityInstance according to the worklist node The JSONObject is also written to the log if the log level for com.groiss.smartclient.Util is set at least to DEBUG
-
getAsJSON
public static JSONObject getAsJSON(String nodeId, HttpServletRequest req, String objectId) throws Exception Builds aJSONObject
representation for an object as it's expected by the client side store.- Parameters:
nodeId
- the XML node id. Must be prefixed by the gui id (e.g. standard.mynode).req
- the current servlet request. Required for initializing the data provider of the node.objectId
- the id of the object (in the form of classname:oid)- Returns:
- the JSONObject representing the object.
- Throws:
Exception
-
getAsJSON
Builds aJSONObject
representation for an object as it's expected by the client side store. The content depends on the store definition. The request parameter "nodeid" should contain the GUI-id of a table (alternative, deprecated parameter name: node).- Parameters:
req
- a servlet requestobject
- a persistent object- Returns:
- the JSONObject representing the object.
- Throws:
Exception
-
getAsJSON
Builds aJSONObject
from aMap
of data for a table row. Performs all the serialization (handlesCellValue
,Persistent
,Date
...)- Parameters:
row
- the data- Returns:
- the JSONObject representing the data
- Throws:
Exception
-
userInput
public static String userInput(String parameterName, Consumer<ClientUtil.DialogConfiguration> builder) Can be used to request input from the user during interactive transactions. If the requested parameter is not yet present on theThreadContext.getThreadRequest()
the current transaction is aborted by throwing an exception, and a dialog is presented to the user. After providing a value, the same request is performed a second time. A common use case would be to request data or confirm proceeding in a workflow-postcondition/preprocessing or when saving a form.
Examples:
String name = ClientUtil.userInput("promptTest", dlg -> dlg
.setMessage("whats your name")
.setType(Type.PROMPT));
or:
ClientUtil.userInput("confirmTest", dlg -> dlg
.setMessage("Do you really want to continue?"));
or:
String gender = ClientUtil.userInput("genderTest", dlg -> dlg
.setMessage("Choose your gender:") .setOptions(Arrays.asList(new Pair<>("male","male"), new Pair<>("female","female"), new Pair<>("other","other"))));
To abort the current transaction, a special exception is thrown by this method. Therefore you must not catch any exception thrown by this method to ensure commonBeanManager
-transaction handling kicks in and performs a cleanBeanManager.rollback()
.
userInput(String, Consumer)
doesn't perform any explicit transaction-handling.- Parameters:
parameterName
- the parametername to be used onServletRequest.getParameter(String)
builder
- usually a lambda expression, that configures the passedClientUtil.DialogConfiguration
- Returns:
- the value
-
userInput
@Deprecated(forRemoval=true, since="11.0") public static String userInput(String parameterName, Supplier<ClientUtil.DialogConfiguration> builder) Deprecated, for removal: This API element is subject to removal in a future version.useuserInput(String, Consumer)
insteadCan be used to request input from the user during interactive transactions. If the requested parameter is not yet present on theThreadContext.getThreadRequest()
the current transaction is aborted by throwing an exception, and a dialog is presented to the user. After providing a value, the same request is performed a second time. A common use case would be to request data or confirm proceeding in a workflow-postcondition/preprocessing or when saving a form.
Examples:
String name = ClientUtil.userInput("promptTest", () -> new DialogConfiguration()
.setMessage("whats your name")
.setType(Type.PROMPT));
or:
ClientUtil.userInput("confirmTest", () -> new DialogConfiguration()
.setMessage("Do you really want to continue?"));
or:
String gender = ClientUtil.userInput("genderTest", () -> new DialogConfiguration()
.setMessage("Choose your gender:") .setOptions(Arrays.asList(new Pair<>("male","male"), new Pair<>("female","female"), new Pair<>("other","other"))));
To abort the current transaction, a special exception is thrown by this method. Therefore you must not catch any exception thrown by this method to ensure commonBeanManager
-transaction handling kicks in and performs a cleanBeanManager.rollback()
.
userInput(String, Supplier)
doesn't perform any explicit transaction-handling.- Parameters:
parameterName
- the parametername to be used onServletRequest.getParameter(String)
builder
- usually a lambda expression, that provides aClientUtil.DialogConfiguration
to be used- Returns:
- the value
-
userInput(String, Consumer)
instead