FormUtil.setFormBuilderActive(true);
// load form definition
model.addAttribute("appId", appId);
AppDefinition appDef = appService.getAppDefinition(appId, version);
FormDefinition formDef = null;
if (appDef == null) {
// TODO: handle invalid app
} else {
model.addAttribute("appDefinition", appDef);
formDef = formDefinitionDao.loadById(formId, appDef);
}
if (formDef != null) {
String formJson = null;
if (json != null && !json.trim().isEmpty()) {
// read custom JSON from request
formJson = json;
} else {
// get JSON from form definition
formJson = formDef.getJson();
}
if (formJson != null && formJson.trim().length() > 0) {
String processedformJson = PropertyUtil.propertiesJsonLoadProcessing(formJson);
try {
FormUtil.setProcessedFormJson(processedformJson);
String elementHtml = formService.previewElement(formJson);
model.addAttribute("elementHtml", elementHtml);
model.addAttribute("elementJson", processedformJson);
} finally {
FormUtil.clearProcessedFormJson();
}
} else {
// default empty form
String tableName = formDef.getTableName();
if (tableName == null || tableName.isEmpty()) {
tableName = formDef.getId();
}
String escapedFormName = StringEscapeUtils.escapeJavaScript(formDef.getName());
String defaultJson = "{className: 'org.joget.apps.form.model.Form', \"properties\":{ \"id\":\"" + formId + "\", \"name\":\"" + escapedFormName + "\", \"tableName\":\"" + tableName + "\", \"loadBinder\":{ \"className\":\"org.joget.apps.form.lib.WorkflowFormBinder\" }, \"storeBinder\":{ \"className\":\"org.joget.apps.form.lib.WorkflowFormBinder\" } }}";
String formHtml = formService.previewElement(defaultJson);
model.addAttribute("elementHtml", formHtml);
}
} else {