java - JSP Servlet/Activiti - 有没有办法通过一次提交 2 个表单来一次完成 2 个任务?

标签 java forms jsp servlets activiti

我正在制作一个使用 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来电。但在这种情况下,您必须在客户端(浏览器)端执行类似的同步。

但是,一般来说,更好的方法是简化您的设计并具有简单且单一的请求/响应。

关于java - JSP Servlet/Activiti - 有没有办法通过一次提交 2 个表单来一次完成 2 个任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29899242/

相关文章:

java - 无法从 editText 获取文本

java - Gradle 无法解析 Android Studio 中的依赖项

python - 如何使用 Python Bottle 框架删除确认表单重新提交

java - 无法为论坛创建答案表?

java - 如何在JSP Servlet中检查密码是否输入错误3次?

javascript - 如何防止表单的只读字段数据?

java - PHP Java 桥 - JEE 服务器

java - Windows Server 上 Tomcat 中的 Spnego keytab 身份验证失败

python - 从 Django 的一页获取选定单选按钮的值

html - Bootstrap3 单选按钮不适用于键盘