1. opensymphony
  2. xwork


xwork / docs / fieldvalidator.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <title>XWork Documentation</title>
  <link type="text/css" href="main.css" rel="STYLESHEET"/>
  <div id="page-logo">
    <a href="index.html"><img src="logo.png" border="0"/></a>
    <div class="snip-title">
	  <h1 class="snip-name">Using the VisitorFieldValidator
<div id="snip-content" class="snip-content">

 <div class="snip-attachments"></div>
 see the <a href="validation.html">Xwork Validation Framework</a>
<h3 class="heading-1">What is the VisitorFieldValidator
</h3><p class="paragraph"/>The VisitorFieldValidator allows you to forward validation to object properties of your action using the objects own validation files. This allows you to use the ModelDriven development pattern and manage your validations for your models in one place, where they belong, next to your model classes. The VisitorFieldValidator can handle either simple Object properties, Collections of Objects, or Arrays.
<h3 class="heading-1">Applying the VisitorFieldValidator
</h3><p class="paragraph"/>The VisitorFieldValidator is applied like any other field validator in a validation.xml file (see <a href="validation.html">Xwork Validation Framework</a>).<p class="paragraph"/><div class="code"><pre>&#60;field name=<span class="java&#45;quote">"bean"</span>&#62;
    &#60;field&#45;validator type=<span class="java&#45;quote">"visitor"</span>&#62;
        &#60;param name=<span class="java&#45;quote">"context"</span>&#62;anotherContext&#60;/param&#62;
        &#60;message&#62;bean: &#60;/message&#62;
&#60;/field&#62;</pre></div><p class="paragraph"/><b class="bold">context</b> is the single parameter available to be set on the VisitorFieldValidator. If set, this sets the context to use for validating the Object property. If not set, the context of the Action validation is propogated to the Object property validation. In the case of Action validation, this context is the Action alias. Here we see the context being overridden in the validator mapping, so the action alias context will not be propogated.<p class="paragraph"/>The <b class="bold">message</b> for the VisitorFieldValidator gives a String which will be appended in front of validation messages added by the validations for the Object message.<p class="paragraph"/>