@Override public Field getPropertyField(FormProperty formProperty) { SelectUserField selectUserField = new SelectUserField(getPropertyLabel(formProperty)); selectUserField.setRequired(formProperty.isRequired()); selectUserField.setRequiredError( getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty))); selectUserField.setEnabled(formProperty.isWritable()); if (formProperty.getValue() != null) { selectUserField.setValue(formProperty.getValue()); } return selectUserField; }
/** * Returns all values filled in in the writable fields on the form. * * @throws InvalidValueException when a validation error occurs. */ public Map<String, String> getFormPropertyValues() throws InvalidValueException { // Commit the form to ensure validation is executed form.commit(); Map<String, String> formPropertyValues = new HashMap<String, String>(); // Get values from fields defined for each form property for (FormProperty formProperty : formProperties) { if (formProperty.isWritable()) { Field field = form.getField(formProperty.getId()); FormPropertyRenderer renderer = getRenderer(formProperty); String fieldValue = renderer.getFieldValue(formProperty, field); formPropertyValues.put(formProperty.getId(), fieldValue); } } return formPropertyValues; }
/** * 根据输入的参数生成提交数据,process和task通用 * * @param hasFormKey * @param formProperties * @param request * @return */ private Map<String, String> generateFormValueMap( boolean hasFormKey, List<FormProperty> formProperties, HttpServletRequest request) { Map<String, String> formValues = new HashMap<String, String>(); if (hasFormKey) { // 外置表单 Map<String, String[]> parameterMap = request.getParameterMap(); Set<Entry<String, String[]>> entrySet = parameterMap.entrySet(); for (Entry<String, String[]> entry : entrySet) { String key = entry.getKey(); formValues.put(key, entry.getValue()[0]); } } else { // 动态表单 for (FormProperty prop : formProperties) { if (prop.isWritable()) { String value = request.getParameter(prop.getId()); formValues.put(prop.getId(), value); } } } return formValues; }
/** * 完成任务 * * @return */ public String completeTask() { HttpServletRequest request = ServletActionContext.getRequest(); IdentityService identityService = processEngine.getIdentityService(); identityService.setAuthenticatedUserId(SpringSecurityUtils.getCurrentUsername()); FormService formService = processEngine.getFormService(); TaskFormData taskFormData = formService.getTaskFormData(taskId); Map<String, String> map = new HashMap<String, String>(); for (FormProperty formProperty : taskFormData.getFormProperties()) { if (formProperty.isWritable()) { String name = formProperty.getId(); map.put(name, request.getParameter(name)); } } formService.submitTaskFormData(taskId, map); return RELOAD; }