Search in sources :

Example 1 with TagWriter

use of org.springframework.web.servlet.tags.form.TagWriter in project spring-framework by spring-projects.

the class BindTagTests method nestingInFormTag.

/**
	 * SPR-4022
	 */
@SuppressWarnings("serial")
@Test
public void nestingInFormTag() throws JspException {
    PageContext pc = createPageContext();
    TestBean tb = new TestBean();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "tb");
    CustomDateEditor l = new CustomDateEditor(df, true);
    binder.registerCustomEditor(Date.class, l);
    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());
    FormTag formTag = new FormTag() {

        @Override
        protected TagWriter createTagWriter() {
            return new TagWriter(new StringWriter());
        }
    };
    String action = "/form.html";
    String commandName = "tb";
    String name = "formName";
    String enctype = "my/enctype";
    String method = "POST";
    String onsubmit = "onsubmit";
    String onreset = "onreset";
    String cssClass = "myClass";
    String cssStyle = "myStyle";
    String acceptCharset = "iso-8859-1";
    formTag.setName(name);
    formTag.setCssClass(cssClass);
    formTag.setCssStyle(cssStyle);
    formTag.setAction(action);
    formTag.setModelAttribute(commandName);
    formTag.setEnctype(enctype);
    formTag.setMethod(method);
    formTag.setOnsubmit(onsubmit);
    formTag.setOnreset(onreset);
    formTag.setAcceptCharset(acceptCharset);
    formTag.setPageContext(pc);
    formTag.doStartTag();
    BindTag bindTag1 = new BindTag();
    bindTag1.setPageContext(pc);
    bindTag1.setPath("date");
    bindTag1.doStartTag();
    bindTag1.doEndTag();
    BindTag bindTag2 = new BindTag();
    bindTag2.setPageContext(pc);
    bindTag2.setPath("tb.date");
    bindTag2.doStartTag();
    bindTag2.doEndTag();
    BindTag bindTag3 = new BindTag();
    bindTag3.setPageContext(pc);
    bindTag3.setPath("tb");
    bindTag3.doStartTag();
    bindTag3.doEndTag();
    formTag.doEndTag();
}
Also used : FormTag(org.springframework.web.servlet.tags.form.FormTag) StringWriter(java.io.StringWriter) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) CustomDateEditor(org.springframework.beans.propertyeditors.CustomDateEditor) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ServletRequestDataBinder(org.springframework.web.bind.ServletRequestDataBinder) TagWriter(org.springframework.web.servlet.tags.form.TagWriter) PageContext(javax.servlet.jsp.PageContext) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

StringWriter (java.io.StringWriter)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 PageContext (javax.servlet.jsp.PageContext)1 Test (org.junit.Test)1 CustomDateEditor (org.springframework.beans.propertyeditors.CustomDateEditor)1 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)1 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)1 TestBean (org.springframework.tests.sample.beans.TestBean)1 ServletRequestDataBinder (org.springframework.web.bind.ServletRequestDataBinder)1 FormTag (org.springframework.web.servlet.tags.form.FormTag)1 TagWriter (org.springframework.web.servlet.tags.form.TagWriter)1