JavaScud | Forum | JIRA | Blog |
  Dashboard > WebWork2文档中文化计划 > ... > Validation > Using Non Field Validators
  WebWork2文档中文化计划 Log In View a printable version of the current page.  
  Using Non Field Validators
Added by scud, last edited by scud on Apr 30, 2006  (view change)
Labels: 
(None)

说明

下面展示了在Webwork中使用非字段校验器(Non Field Validators)的一个简单例子.

第一步

创建jsp页面

<ww:actionerror />
	
<ww:form method="POST" action="submitNonFieldValidatorsExamples" namespace="/validation">
	<ww:textfield name="someText" label="Some Text" />
	<ww:textfield name="someTextRetype" label="Retype Some Text" />  
	<ww:textfield name="someTextRetypeAgain" label="Retype Some Text Again" />
	<ww:submit label="Submit" />
</ww:form>

第二步

创建action类

public class NonFieldValidatorsExampleAction extends AbstractValidationActionSupport {
	
	private String someText;
	private String someTextRetype;
	private String someTextRetypeAgain;
	
	public String getSomeText() {
		return someText;
	}
	public void setSomeText(String someText) {
		this.someText = someText;
	}
	public String getSomeTextRetype() {
		return someTextRetype;
	}
	public void setSomeTextRetype(String someTextRetype) {
		this.someTextRetype = someTextRetype;
	}
	public String getSomeTextRetypeAgain() {
		return someTextRetypeAgain;
	}
	public void setSomeTextRetypeAgain(String someTextRetypeAgain) {
		this.someTextRetypeAgain = someTextRetypeAgain;
	}
}

第三步

创建validator.xml.

<validators>
	<validator type="expression">
		<param name="expression"><![CDATA[ ( (someText == someTextRetype) && (someTextRetype == someTextRetypeAgain) ) ]]></param>
		<message><![CDATA[ all three text must be exactly the same ]]></message>
	</validator>
</validators>
Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators