org.springframework.web.servlet.tags.form.FormTag Java Examples

The following examples show how to use org.springframework.web.servlet.tags.form.FormTag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormFirstErrorsTag.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get the value for the HTML '<code>id</code>' attribute.
 * <p>Appends '<code>.errors</code>' to the value returned by {@link #getPropertyPath()}
 * or to the model attribute name if the <code>&lt;form:errors/&gt;</code> tag's
 * '<code>path</code>' attribute has been omitted.
 * @return the value for the HTML '<code>id</code>' attribute
 * @see #getPropertyPath()
 */
@Override
protected String autogenerateId() throws JspException {
	String path = getPropertyPath();
	if ("".equals(path) || "*".equals(path)) {
		path = (String) this.pageContext.getAttribute(
				FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	}
	return StringUtils.deleteAny(path, "[]") + ".errors";
}
 
Example #2
Source File: FormErrorsTag.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get the value for the HTML '<code>id</code>' attribute.
 * <p>Appends '<code>.errors</code>' to the value returned by {@link #getPropertyPath()}
 * or to the model attribute name if the <code>&lt;form:errors/&gt;</code> tag's
 * '<code>path</code>' attribute has been omitted.
 * @return the value for the HTML '<code>id</code>' attribute
 * @see #getPropertyPath()
 */
@Override
protected String autogenerateId() throws JspException {
	String path = getPropertyPath();
	if ("".equals(path) || "*".equals(path)) {
		path = (String) this.pageContext.getAttribute(
				FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
	}
	return StringUtils.deleteAny(path, "[]") + ".errors";
}
 
Example #3
Source File: BindTagTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: BindTagTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * 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();
}
 
Example #5
Source File: BindTagTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * 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.setCommandName(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();
}