How to pass htmlform data to the fragment controller

Hi, Here i have a gsp file having the following form information. previewHtml displays the form and the form could be any form. I would like to know how to pass the form data to the fragment controller. @ModelAttribute annotation does not work in the fragment controller.

GSP File:

<script>
function submitHtmlForm() { }

</script>

<form id="htmlform" method="post" onSubmit="submitHtmlForm(); return false;" enctype="multipart/form-data">

${ previewHtml }

</form>

Fragment Controller File:

public void controller(FragmentModel model) throws Exception {

Patient patient = null;
		Form form = null;
		HtmlForm htmlForm = null;
		
		form = Context.getFormService()
				.getForm(7);
		htmlForm = HtmlFormEntryUtil.getService()
				.getHtmlFormByForm(form);
		patient = Context.getPatientService()
				.getPatient(2);
		
		FormEntryContext.Mode mode = FormEntryContext.Mode.ENTER;
		
		FormEntrySession session = new FormEntrySession(patient, htmlForm, mode, null);
		String html = session.getHtmlToDisplay();
		
		if (session.getFieldAccessorJavascript() != null) {
			html += "<script>" + session.getFieldAccessorJavascript() + "</script>";
		}
		
		model.addAttribute("previewHtml", html);
}

Please let me know. Thanks

I don’t quite understand your question. Are you trying to display or submit?

This may help: https://wiki.openmrs.org/x/2gHn

Is there a reason you aren’t using one of the existing fragments and pages in the htmlformentryui module? See them all by going to https://github.com/openmrs/openmrs-module-htmlformentryui/find/master and then typing “htmlform.gsp”.

Hi Darius, Thank you very much for the information. The links really helped me. I was trying to submit the form.

HI, I am getting error when trying to submit the htmlform. Here is the error: org.openmrs.module.htmlformentry.BadFormDesignException: Please check the design of your form to make sure it has all three tags: <encounterDate/&gt;, <encounterLocation/&gt;, and <encounterProvider/>

Please let me know. Thanks

Does your form have those three tags? Can you paste it at pastebin.com for us to see?

Hi Daniel, pastebin, i have some account activation issue and have to wait for somemore time for the activation. Here i have paste the htmlform code.

<!-- Autogenerated example form  (template from 01-Nov-2010 -->
<macros>
	paperFormId = (Fill this in)
	headerColor =#009d8e
	fontOnHeaderColor = white
</macros>

<style>
	.section {
		border: 1px solid $headerColor;
		padding: 2px;
		text-align: left;
		margin-bottom: 1em;
	}
	.sectionHeader {
		background-color: $headerColor;
		color: $fontOnHeaderColor;
		display: block;
		padding: 2px;
		font-weight: bold;
	}
	table.baseline-aligned td {
		vertical-align: baseline;
	}
</style>
table, tr, td { background-color:#E6E6E6; border:1px solid black; border-collapse: collapse; padding: 0.1cm; margin-left: 0.8cm; } body { font-family: "Arial"; font-size: 12px; } body[Attributes Style] { margin-right: 0px; margin-left: 0px; margin-bottom: 0px; margin-top: 0px; } body { display: block; } article, aside, footer, header, hgroup, main, nav, section { display: block; } p { padding-left: 0.8cm; margin-top: 0.0cm; margin-bottom: 0.0cm; } p { display: block; -webkit-margin-before: 1em; -webkit-margin-after: 1em; -webkit-margin-start: 0px; -webkit-margin-end: 0px; } label { cursor: default; } input[type="number"] { width: 6em; } textarea { width: 55em; height: 3em; display: block; } textarea { -webkit-appearance: textarea; background-color: white; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; -webkit-rtl-ordering: logical; -webkit-user-select: text; flex-direction: column; resize: auto; cursor: auto; white-space: pre-wrap; word-wrap: break-word; border-width: 1px; border-style: solid; border-color: initial; padding: 2px; } header.level1 { font-family: "Arial"; font-size: medium; font-weight: bold; margin-top: 0.3cm; margin-bottom: 0.0cm; background-color: white; color: black; } input[type="text"] { width: 20em; } header.level2 { text-align: left; font-family: "Arial"; font-size: small; font-weight: bold; margin-top: 0.3cm; margin-bottom: 0.0cm; background-color: white; color: black; } form input, form select, form textarea, form ul.select, .form input, .form select, .form textarea, .form ul.select { min-width: 30%; color: #363463; display: block; padding: 5px 10px; margin: 0; margin-top: 5px; background-color: #FFF; border: 1px solid #dddddd; } #label_text{ float:left; /* padding-right: 10px; */ padding-right: 1%; } #label_placeholder{ float:right; margin-top: -18px; /* padding-right: 540px; padding-right: 52%; */ } header { position: relative; /* background-color: #00463f; */ color: #CCC; line-height: 1em; -moz-border-radius: 5px; -webkit-border-radius: 5px; -o-border-radius: 5px; -ms-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px; }
<span style="float:right">Paper Form ID: $paperFormId</span>
<h2>Cardiac MRI Adenosine Stress Protocol</h2>

<section headerLabel="1. Encounter Details">
	<table class="baseline-aligned">
		<tr>
			<td>Date:</td>
			<td><encounterDate default="today"/></td>
		</tr>
		<tr>
			<td>Location:</td>
			<td><encounterLocation/></td>
		</tr>
		<tr>
			<td>Provider:</td>
			<td><encounterProvider/></td>
		</tr>
	</table>
</section>
Cardiac MRI: Adenosine Stress Protocol

Field strength: T

Adenosine stress protocol:

Clinical information

Comparison

Findings

Stress perfusion imaging:

Rest perfusion imaging:

Cine images:

Left ventricle

End-diastole volume: mL

End-systolic volume: mL

Stroke volume: mL

Ejection fraction: %

Mass: g

Antero-septal wall (end-diastole): cm

Infero-lateral wall (end-diastole): cm

Left ventricular diameter measured at the base (end-diastole): cm

Left ventricular diameter measured at the base (end-systole): cm

Delayed enhancement:

Reference

Reference values from: Maceira et al., Normalized left ventricular systolic and diastolic function by steady state free precession cardiovascular magnetic resonance. J Cardiovascular Magn Reson 2006; 8:417-426.

Impression

<submit/>

Here is a paste bin link for the htmlform http://pastebin.com/CWdWYzWQ

Can you create your form on uat-refapp.openmrs.org

Hi Daniel, I created a form called Cardiac Adenosine Stress Protocol on uat-refapp.openmrs.org

While on uat-refapp.openmrs.org, are you able to submit the form successfully?

Yes I am able to submit the form successfully on uat-refapp.openmrs.org

On your local instance, try use the same version of the htmlformentry module as on this server.

Yes on my local instance, i am using the same htmlform entry version as uat-refapp.openmrs.org. Below is the version that I have on my local instance.

HTML Form Entry 3.3.0 Darius Jazayeri FormEntry in-webapp, using HTML forms…

Now copy the html form from uat-refapp.openmrs.org to your local server and test it again.

I am able to copy and save the same form from uat-refapp.openmrs.org on my local server. I thought it won’t save because the concepts would not be available but it did saved successfully. Those concepts are already created on my local instance dictionary.

But when i try to display the form on my patient dashboard, it is showing error message,

UI Framework Error Root Error java.lang.RuntimeException: Cannot handle datatype: N/A (for concept 163141) at org.openmrs.module.htmlformentry.element.ObsSubmissionElement.prepareWidgets(ObsSubmissionElement.java:880) at org.openmrs.module.htmlformentry.element.ObsSubmissionElement.(ObsSubmissionElement.java:215) at org.openmrs.module.htmlformentry.handler.ObsTagHandler.doStartTag(ObsTagHandler.java:43) at org.openmrs.module.htmlformentry.HtmlFormEntryGenerator.applyTagsHelper(HtmlFormEntryGenerator.java:516) at org.openmrs.module.htmlformentry.HtmlFormEntryGenerator.applyTagsHelper(HtmlFormEntryGenerator.java:533) at org.openmrs.module.htmlformentry.HtmlFormEntryGenerator.applyTagsHelper(HtmlFormEntryGenerator.java:533) at org.openmrs.module.htmlformentry.HtmlFormEntryGenerator.applyTagsHelper(HtmlFormEntryGenerator.java:533) at org.openmrs.module.htmlformentry.HtmlFormEntryGenerator.applyTags(HtmlFormEntryGenerator.java:489) at org.openmrs.module.htmlformentry.FormEntrySession.createForm(FormEntrySession.java:414) at org.openmrs.module.htmlformentry.FormEntrySession.getHtmlToDisplay(FormEntrySession.java:796) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl$GetBeanMethodMetaProperty.getProperty(MetaClassImpl.java:3468) at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:235) at SimpleTemplateScript35.run(SimpleTemplateScript35.groovy:133) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:165) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:177) at org.openmrs.ui.framework.fragment.GroovyFragmentView.render(GroovyFragmentView.java:46) at org.openmrs.ui.framework.fragment.FragmentFactory.processThisFragment(FragmentFactory.java:187) at org.openmrs.ui.framework.fragment.FragmentFactory.process(FragmentFactory.java:116) at org.openmrs.ui.framework.page.PageContext.includeFragment(PageContext.java:75) at org.openmrs.ui.framework.UiUtils.includeFragment(UiUtils.java:157) at sun.reflect.GeneratedMethodAccessor861.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:132) at SimpleTemplateScript34.run(SimpleTemplateScript34.groovy:31) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:165) at groovy.text.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:177) at org.openmrs.ui.framework.page.GroovyPageView.render(GroovyPageView.java:43) at org.openmrs.ui.framework.page.PageFactory.processThisFragment(PageFactory.java:185) at org.openmrs.ui.framework.page.PageFactory.process(PageFactory.java:114)

Replace all form concept ids with the ones on your local server. Ensure that they also have the same data types as on the uat server.

I created new concepts on my local server and replaced all form concepts ids with the new ones on my local server. All have the same data types.

I am able to submit the form from patient dashboard. But when i use the part of the htmlformentryui code on my module, am getting the error

org.openmrs.module.htmlformentry.BadFormDesignException: Please check the design of your form to make sure it has all three tags: <encounterDate/>, <encounterLocation/>, and

Thank you @darius and @dkayiwa. I am able to get the htmlform working.

@tibwangchuk what was the problem?