【发布时间】:2021-10-12 11:18:21
【问题描述】:
查看表单时,我需要添加对通过 URL 参数将字段值传递给表单的支持,该表单将用于在加载时将值填充到表单中。应支持字段名称和值的 JSON 格式值。示例:
https://web/form/view?id=1&data={'fieldname':'value'}
@RequestMapping(value = "/form/view", method = RequestMethod.GET)
public ModelAndView viewDomainForm(HttpSession session, @ModelAttribute("command") FormBean inFormBean) {
Form form = formService.getForm(inFormBean.getId());
FormInstance formInstance = formInstanceService.createFormInstance(form);
String formInstanceId = (String) session.getAttribute("formInstanceId");
if (formInstanceId != null && formInstanceId.length() > 0) {
formInstanceService.deleteFormInstanceById(formInstanceId);
}
formInstanceId = formInstance.getId();
session.setAttribute("formInstanceId", formInstanceId);
FormBean formBean = prepareFormBean(form);
formBean.setEmbed(inFormBean.isEmbed());
formBean.setFormInstanceId(formInstance.getId());
Map<String, Object> model = new HashMap<String, Object>();
model.put("externalBaseUrl", configurationService.getValue("core.external.url.base"));
model.put("fromTaskList", false);
model.put("form", formBean);
model.put("flow", new FlowBean());
model.put("task", new TaskBean());
return new ModelAndView("form-viewer", model);
}
我有这种查看方法。从 URL 参数填充字段的最佳方法是什么?
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
// this is the value that will populate into the form when it loads.
【问题讨论】:
标签: java json spring-boot