FormService formService = (FormService) ac.getBean("formService");
WorkflowManager workflowManager = (WorkflowManager) ac.getBean("workflowManager");
Form form = null;
WorkflowAssignment assignment = null;
FormData formData = new FormData();
// get assignment by activity ID if available
if (activityId != null && !activityId.trim().isEmpty()) {
assignment = workflowManager.getAssignment(activityId);
}
if (assignment == null) {
// assignment not available, attempt to load assignment by process ID
assignment = workflowManager.getAssignmentByProcess(processId);
}
if (assignment != null) {
// load assignment form
PackageActivityForm activityForm = retrieveAssignmentForm(formData, assignment);
// submit assignment form
form = submitAssignmentForm(formData, assignment, activityForm);
} else {
// load data form
form = retrieveDataForm(formData, id);
// submit data form
form = submitDataForm(formData, form);
}
// determine redirect URL
String redirectUrl = getPropertyString("redirectUrlAfterComplete");
if (redirectUrl != null && redirectUrl.trim().length() > 0 && getPropertyString("fieldPassover") != null && getPropertyString("fieldPassover").trim().length() > 0) {
String passoverFieldName = getPropertyString("fieldPassover");
Element passoverElement = FormUtil.findElement(passoverFieldName, form, formData);
String passoverValue = "";
if (passoverElement != null) {
passoverValue = FormUtil.getElementPropertyValue(passoverElement, formData);
} else if (FormUtil.PROPERTY_ID.equals(passoverFieldName)) {
passoverValue = formData.getPrimaryKeyValue();
}
if ("append".equals(getPropertyString("fieldPassoverMethod"))) {
if (!redirectUrl.endsWith("/")) {
redirectUrl += "/";
}
redirectUrl += passoverValue;
} else {
if (redirectUrl.contains("?")) {
redirectUrl += "&";
} else {
redirectUrl += "?";
}
redirectUrl += getPropertyString("paramName") + "=" + passoverValue;
}
}
if (form != null) {
// generate form HTML
String formHtml = null;
// check for validation errors
Map<String, String> errors = formData.getFormErrors();
int errorCount = 0;
if (!formData.getStay() && errors == null || errors.isEmpty()) {
// render normal template
formHtml = formService.generateElementHtml(form, formData);
setAlertMessage(getPropertyString("messageShowAfterComplete"));
boolean redirectToParent = "Yes".equals(getPropertyString("showInPopupDialog"));
setRedirectUrl(redirectUrl, redirectToParent);
} else {
// render error template
formHtml = formService.generateElementErrorHtml(form, formData);
errorCount = errors.size();
}
if (formData.getStay()) {
setAlertMessage("");
setRedirectUrl("");
}
// show form
String formJson = formService.generateElementJson(form);
setProperty("view", "formView");
setProperty("errorCount", errorCount);
setProperty("stay", formData.getStay());
setProperty("submitted", Boolean.TRUE);
setProperty("formHtml", formHtml);
setProperty("formJson", formJson);
setProperty("redirectUrlAfterComplete", redirectUrl);
if (assignment != null) {