/** * Performs smart form population. */ @Override public int doAfterBody() throws JspException { BodyContent body = getBodyContent(); JspWriter out = body.getEnclosingWriter(); String bodytext = populateForm(body.getString(), name -> value(name, pageContext)); try { out.print(bodytext); } catch (IOException ioex) { throw new JspException(ioex); } return SKIP_BODY; }
static String form1(String form) { FormTag ft = new FormTag(); return ft.populateForm(form, foo); }
/** * Performs smart form population. */ @Override public int doAfterBody() throws JspException { BodyContent body = getBodyContent(); JspWriter out = body.getEnclosingWriter(); String bodytext = populateForm(body.getString(), name -> value(name, pageContext)); try { out.print(bodytext); } catch (IOException ioex) { throw new JspException(ioex); } return SKIP_BODY; }
static String form2(String form) { return new FormTag().populateForm(form, foo2); }
static String form(String form) { String result = new FormTag().populateForm(form, foo); assertEquals(result, form1(form)); return result; }
@Test void testMultipleInputs() { String form = "<input type=\"text\" name=\"cc\" id=\"cc1\"/>\n" + "<input type=\"text\" name=\"cc\" id=\"cc2\" />\n" + "<input type=\"text\" name=\"cc\" id=\"cc3\" />"; FormTag ft = new FormTag(); String populatedForm = ft.populateForm(form, new FormFieldResolver() { public Object value(String name) { return new String[] {"a@b.c", "c@d.e", "e@f.g"}; } }); assertEquals( "<input type=\"text\" name=\"cc\" id=\"cc1\" value=\"a@b.c\"/>\n" + "<input type=\"text\" name=\"cc\" id=\"cc2\" value=\"c@d.e\"/>\n" + "<input type=\"text\" name=\"cc\" id=\"cc3\" value=\"e@f.g\"/>", populatedForm); }