JSP Servlet / Activiti - 有没有办法通过一次提交 2 个表单来一次完成 2 个任务?
JSP Servlet / Activiti - Is there a way to complete 2 tasks at once by submitting 2 forms at once?
我正在制作一个使用 Activiti 的网络应用程序,它有 2 个并行任务,我希望用户能够同时完成这些任务。我不太清楚如何做到这一点。我玩弄过提交一个大表格的想法,然后将在服务器上拆分,但我不确定如何去做。理想情况下,我一次提交 2 个表格似乎是合乎逻辑的方式,但我不确定这是否可能。
我的JSP表格:
<form action="CompleteTask" method="post">
<c:forEach items="${formProperties}" var="property" varStatus="status">
${property.getName()}:
<br />
<c:set var="type" value="${property.getType().getName()}" />
<c:if test="${type == 'string'}">
<c:if test="${property.isRequired() == 'true' }">
<input type="text" name="${property.getId()}" value="${property.getValue()}" required /><br />
</c:if>
<c:if test="${property.isRequired() == 'false' }">
<input type="text" name="${property.getId()}" value="" /><br />
</c:if>
</c:if>
<c:if test="${type == 'long'}">
<c:if test="${property.isRequired() == 'true' }">
<input type="text" name="${property.getId()}" value="${property.getValue()}" required /><br />
</c:if>
<c:if test="${property.isRequired() == 'false' }">
<input type="text" name="${property.getId()}" value="" /><br />
</c:if>
</c:if>
<c:if test="${type == 'date'}">
<c:if test="${property.isRequired() == 'true' }">
<input type="date" name="${property.getId()}" value="" required /><br />
</c:if>
<c:if test="${property.isRequired() == 'false' }">
<input type="date" name="${property.getId()}" value="" /><br />
</c:if>
</c:if>
<c:if test="${type == 'enum'}">
<select name="${property.getId()}">
<c:forEach var="entry" items='${property.getType().getInformation("values")}'>
<option value="${entry.key}">${entry.value}</option>
</c:forEach>
</select><br /><br />
</c:if>
</c:forEach>
<input type="hidden" id="taskId" name="taskId" value="${taskList.get(0).getId()}" /><br />
</form>
此表单位于 forEach 循环中,因此会根据任务数量(在本例中为 2 个)制作多个版本。
我当前用于完成任务的 servlet 代码:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
Map<String, Object> params = new HashMap<String, Object>();
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String paramName = parameterNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
String paramValue = paramValues[0];
if(!paramName.equals("submit")){
System.out.println(paramName+ " - " + paramValue);
params.put(paramName, paramValue);
}
}
String taskId = request.getParameter("taskId");
TaskService taskService = processEngine.getTaskService();
Task t = taskService.createTaskQuery().taskId(taskId).singleResult();
taskService.complete(t.getId(), params);
你是对的 - 最好创建一个请求,然后在服务器端 运行 2 个进程。但是,您必须同步这些过程,获得两个答案,然后将它们合并为一个完整答案。
另一种方法是进行 2 次 AJAX 调用。但是在这种情况下,您必须在客户端(浏览器)端进行类似的同步。
但是,一般来说,更好的方法是简化您的设计并保持简单和单一 request/response。
我不确定需要并行流程但只需要单个用户任务的业务案例。似乎你可以收集你需要的信息然后分支。但是,如果业务逻辑要求您必须使用此模式,那么 BPMN 确实支持 messaging/signals 的功能。
在并行路径之一上使用单个用户表单。其他路径没有用户任务,而是在等待消息或信号。
然后在收集到您需要的详细信息后,使用信号发送事件任务到 "release" 其他并行路径。
我正在制作一个使用 Activiti 的网络应用程序,它有 2 个并行任务,我希望用户能够同时完成这些任务。我不太清楚如何做到这一点。我玩弄过提交一个大表格的想法,然后将在服务器上拆分,但我不确定如何去做。理想情况下,我一次提交 2 个表格似乎是合乎逻辑的方式,但我不确定这是否可能。
我的JSP表格:
<form action="CompleteTask" method="post">
<c:forEach items="${formProperties}" var="property" varStatus="status">
${property.getName()}:
<br />
<c:set var="type" value="${property.getType().getName()}" />
<c:if test="${type == 'string'}">
<c:if test="${property.isRequired() == 'true' }">
<input type="text" name="${property.getId()}" value="${property.getValue()}" required /><br />
</c:if>
<c:if test="${property.isRequired() == 'false' }">
<input type="text" name="${property.getId()}" value="" /><br />
</c:if>
</c:if>
<c:if test="${type == 'long'}">
<c:if test="${property.isRequired() == 'true' }">
<input type="text" name="${property.getId()}" value="${property.getValue()}" required /><br />
</c:if>
<c:if test="${property.isRequired() == 'false' }">
<input type="text" name="${property.getId()}" value="" /><br />
</c:if>
</c:if>
<c:if test="${type == 'date'}">
<c:if test="${property.isRequired() == 'true' }">
<input type="date" name="${property.getId()}" value="" required /><br />
</c:if>
<c:if test="${property.isRequired() == 'false' }">
<input type="date" name="${property.getId()}" value="" /><br />
</c:if>
</c:if>
<c:if test="${type == 'enum'}">
<select name="${property.getId()}">
<c:forEach var="entry" items='${property.getType().getInformation("values")}'>
<option value="${entry.key}">${entry.value}</option>
</c:forEach>
</select><br /><br />
</c:if>
</c:forEach>
<input type="hidden" id="taskId" name="taskId" value="${taskList.get(0).getId()}" /><br />
</form>
此表单位于 forEach 循环中,因此会根据任务数量(在本例中为 2 个)制作多个版本。
我当前用于完成任务的 servlet 代码:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
Map<String, Object> params = new HashMap<String, Object>();
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String paramName = parameterNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
String paramValue = paramValues[0];
if(!paramName.equals("submit")){
System.out.println(paramName+ " - " + paramValue);
params.put(paramName, paramValue);
}
}
String taskId = request.getParameter("taskId");
TaskService taskService = processEngine.getTaskService();
Task t = taskService.createTaskQuery().taskId(taskId).singleResult();
taskService.complete(t.getId(), params);
你是对的 - 最好创建一个请求,然后在服务器端 运行 2 个进程。但是,您必须同步这些过程,获得两个答案,然后将它们合并为一个完整答案。
另一种方法是进行 2 次 AJAX 调用。但是在这种情况下,您必须在客户端(浏览器)端进行类似的同步。
但是,一般来说,更好的方法是简化您的设计并保持简单和单一 request/response。
我不确定需要并行流程但只需要单个用户任务的业务案例。似乎你可以收集你需要的信息然后分支。但是,如果业务逻辑要求您必须使用此模式,那么 BPMN 确实支持 messaging/signals 的功能。 在并行路径之一上使用单个用户表单。其他路径没有用户任务,而是在等待消息或信号。 然后在收集到您需要的详细信息后,使用信号发送事件任务到 "release" 其他并行路径。