@Test public void shouldBuildSchemaWithSections() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("sections").get(1).get("name").getValueAsText(), is("Section 2")); }
@Test public void shouldBuildSchemaWithSectionsNestedSections() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); HtmlFormSection section1a = new HtmlFormSection(); section1a.setName("Section 1a"); section1.addChildSection(section1a); HtmlFormSection section1b = new HtmlFormSection(); section1b.setName("Section 1b"); section1.addChildSection(section1b); schema.getSections().add(section1); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("sections").get(0).get("sections").get(0).get("name").getValueAsText(), is("Section 1a")); assertThat(schemaAsJson.get("sections").get(0).get("sections").get(1).get("name").getValueAsText(), is("Section 1b")); assertThat(schemaAsJson.get("sections").get(1).get("name").getValueAsText(), is("Section 2")); }
@Test public void shouldBuildSchemaWithSectionAndSeparateField() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); ObsField field1 = new ObsField(); field1.setName("Field 1"); schema.getFields().add(field1); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("fields").get(0).get("name").getValueAsText(), is("Field 1")); }
@Override public boolean doStartTag(FormEntrySession session, PrintWriter out, Node parent, Node node) { String sectionTag = getAttribute(node, "sectionTag", "div"); String headerTag = getAttribute(node, "headerTag", "span"); String sectionStyleClass = getAttribute(node, "sectionStyle", "section"); String headerStyleClass = getAttribute(node, "headerStyle", "sectionHeader"); String sectionId = getAttribute(node, "id", null); String headerLabel = getAttribute(node, "headerLabel", null); if (headerLabel == null) { String headerCode = getAttribute(node, "headerCode", null); if (headerCode != null) { Translator trans = session.getContext().getTranslator(); headerLabel = trans.translate(Context.getLocale().toString(), headerCode); } } out.print("<" + sectionTag + " class=\""+sectionStyleClass + "\""); if (sectionId != null) { out.print(" id=\"" + sectionId + "\""); } out.print(">"); if (headerLabel != null) { out.print("<" + headerTag + " class=\""+headerStyleClass+"\">"+headerLabel+"</" + headerTag + ">"); } session.getContext().beginSection(); session.getContext().getActiveSection().setName(headerLabel); return true; }
section1.setName("Section 1"); schema.getSections().add(section1);
section1.setName("Section 1"); schema.getSections().add(section1);