对于jQuery移动版,我需要这样的标记:
<form action="..." method="get" data-ajax="false">
<!-- Fields -->
</form>因为我使用的是Spring,所以我真的很喜欢<form:form>为我做的事情,包括所有方便的绑定、生成字段等。
如何让<form:form>打印额外的属性?
发布于 2011-11-30 03:11:46
<form:form>标记将允许任意属性。
<form:form commandName="blah" data-ajax="false">将会工作得很好。
发布于 2011-08-11 15:13:57
您可以创建一个扩展标准Spring标记的自定义JSP标记。通过覆盖writeOptionalAttributes方法,您可以添加所需的其他属性。例如
public class FormTag
extends org.springframework.web.servlet.tags.form.FormTag {
private String dataAjax;
/* (non-Javadoc)
* @see org.springframework.web.servlet.tags.form.AbstractHtmlElementTag#writeOptionalAttributes(org.springframework.web.servlet.tags.form.TagWriter)
*/
@Override
protected void writeOptionalAttributes(final TagWriter tagWriter) throws JspException {
super.writeOptionalAttributes(tagWriter);
writeOptionalAttribute(tagWriter, "data-ajax", getDataAjax());
}
/**
* Returns the value of dataAjax
*/
public String getDataAjax() {
return dataAjax;
}
/**
* Sets the value of dataAjax
*/
public void setDataAjax(String dataAjax) {
this.dataAjax = dataAjax;
}
}然后,您需要使用定制的TLD,以使新属性可用于JSP引擎。我在这里只展示了它的一小段,因为它是从Spring原始文件复制并粘贴的,只是添加了您的附加属性。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>custom-form</short-name>
<uri>http://www.your.domain.com/tags/form</uri>
<description>Custom Form Tag Library</description>
<!-- <form:form/> tag -->
<tag>
<name>form</name>
<tag-class>com.your.package.tag.spring.form.FormTag</tag-class>
<body-content>JSP</body-content>
<description>Renders an HTML 'form' tag and exposes a
binding path to inner tags for binding.</description>
<attribute>
<name>id</name>
<rtexprvalue>true</rtexprvalue>
<description>HTML Standard Attribute</description>
</attribute>
....
<attribute>
<name>dataAjax</name>
<rtexprvalue>true</rtexprvalue>
<description>jQuery data ajax attribute</description>
</attribute><%@ taglib prefix="custom-form" uri="http://www.your.domain.com/tags/form" %>而不是使用
<form:form> 使用
<custom-form:form dataAjax="false"> https://stackoverflow.com/questions/6912755
复制相似问题