xwork / docs / wikidocs / Generic Object Validation.html

Full commit
        <title>XWork : Generic Object Validation</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    

	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            XWork : Generic Object Validation
				    <div class="pagesubheading">
					    This page last changed on Jun 03, 2004 by <font color="#0050B2">unkyaku</font>.

				    <p class="paragraph">XWork&#039;s validation framework is not just limited to Actions.  It can be used to validate virtually any object.  Once you&#039;ve set up your validator config file (<b class="strong">validators.xml</b>) and your validation rules (<b class="strong">ClassName-validation.xml</b>), all it takes are a couple lines of code:</p><div class="code"><div class="codeContent">
<pre><span class="java&#45;object">String</span> context = <span class="java&#45;keyword">null</span>;&#10;ValidatorContext context = <span class="java&#45;keyword">new</span> DelegatingValidatorContext(objectToValidate);&#10;ActionValidatorManager.validate(objectToValidate, <span class="java&#45;keyword">null</span>, context);</pre>
</div></div><p class="paragraph">This will cause any errors to be logged (where it gets logged to depends on how commons-logging is configured).</p>Ideally, you would either implement your own ValidatorContext to handle how error messages are logged and evaluated, or have your objects that are to be evaluated implement ValidationAware, TextProvider and/or LocaleProvider.<p class="paragraph">Matthew Payne has a JUnit demo of this at <a href="" title="Visit page outside Confluence">&#104;ttp://</a>.</p>

	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
				<td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td>
			    <td align="center"><font color="grey">Document generated by Confluence on Dec 12, 2004 12:35</font></td>