HTMLFormEntry是一种非常有效的表单保存方式。您创建XML并且模块处理在按下提交时将输入转换为数据库记录。
我们如何呈现表单,例如在path/to/form.xml
?
我们是否必须在自己的页面中呈现它,还是可以将其加载到页面中?
答案 0 :(得分:0)
选项1 :使用public void HtmlFormEntry.HtmlForm.setXmlData(String xmlData)
import org.openmrs.module.htmlformentry.HtmlForm;
...
HtmlForm form = new HtmlForm();
form.setXmlData(xml);
选项2 :如果您的XML尚未加载,请使用public static HtmlForm HtmlFormEntryUI.HtmlFormUtil.getHtmlFormFromUiResource(<arguments>)
,reference
relativeWebResourcePath
是模块目录/omod/src/main/webapp/resources
的相对路径。 ResourceFactory resourceFactory, FormService formService, HtmlFormEntryService htmlFormEntryService, String providerAndPath
import org.openmrs.api.FormService;
import org.openmrs.module.htmlformentry.HtmlFormEntryService;
import org.openmrs.module.htmlformentry.HtmlForm;
import org.openmrs.module.htmlformentryui.HtmlFormUtil;
...
String htmlFormPath = thisModuleName+":"+relativeWebResourcePath;
ResourceFactory resourceFactory = ResourceFactory.getInstance();
FormService formService = Context.getFormService();
HtmlFormEntryService htmlFormEntryService = Context.getService(HtmlFormEntryService.class);
HtmlForm form = HtmlFormUtil.getHtmlFormFromUiResource(resourceFactory, formService, htmlFormEntryService, htmlFormPath);
import org.openmrs.module.htmlformentry.FormEntrySession;
...
FormEntrySession fes = new FormEntrySession(patient, form, request.session)
String html = fes.getHtmlToDisplay()
生成的FormEntrySession
对象的html应包含提交表单所需的所有逻辑。