如继往还需要一个FormDefinitionService和FormDefinitionService,不需要为它们添加任何额外实现直接继承自DaoBase就可以了,因为jbpm也使用hibernate哦!而我们的DaoBase是一个通用的数据库基本操作。
DispatchAction:
1.表单定义列表
/** * 显示自定义表单列表 */ public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 查询数据列表并将信息添加到request的formDefinitionList属性中 List<FormDefinition> formDefinitionList = formDefinitionService.findAll(); request.setAttribute("formDefinitionList", formDefinitionList); return mapping.findForward("list"); // list.jsp } |
2.显示添加表单页面
/** * 添加自定义表单页面 */ public ActionForward addUI(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 获取自定义表单需要使用的流程信息 List<String> processNameList = processDefinitionService .findAllNameList(); // 将流程信息添加到request中,用于在页面显示 request.setAttribute("processNameList", processNameList); return mapping.findForward("addUI"); // addUI.jsp } |
3.添加表单
/** * 添加自定义表单 */ public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 获取表单提单过来的信息 FormDefinitionActionForm actionForm = (FormDefinitionActionForm) form; // 将ActionForm中的信息封装到FormDefinition中 FormDefinition formDefinition = new FormDefinition(); BeanUtils.copyProperties(formDefinition, actionForm); // 下面就是用户自定义的所有表单字段 for (int i = 0; i < actionForm.getPropertyNameList().length; i++) { String name = actionForm.getPropertyNameList()[i]; Class valueType = actionForm.getPropertyValueTypeList()[i]; // 判断字段名称是否有效 if (name != null && name.trim().length() > 0) { formDefinition.getFieldDefinitionList().put(name, valueType); } } // 保存表单定义 formDefinitionService.save(formDefinition); return mapping.findForward("toList"); } |
4.删除表单
/** * 删除自定义表单 */ public ActionForward del(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 获取将被删除的表单记录id Long id = Long.parseLong(request.getParameter("id")); formDefinitionService.delete(id); return mapping.findForward("toList"); } |