Update reference documentation generation tools to get source highlighting [SPRNET-1045]
This commit is contained in:
@@ -1,6 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<chapter id="validation">
|
||||
<title id="val-title">Validation Framework</title>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<chapter xml:id="validation" xmlns="http://docbook.org/ns/docbook" version="5">
|
||||
<title>Validation Framework</title>
|
||||
|
||||
<section>
|
||||
<title>Introduction</title>
|
||||
@@ -84,7 +101,7 @@
|
||||
validation rules defined for the Trip object in the SpringAir sample
|
||||
application:</para>
|
||||
|
||||
<para><programlisting><objects xmlns="http://www.springframework.net" xmlns:v="http://www.springframework.net/validation">
|
||||
<para><programlisting language="myxml"><objects xmlns="http://www.springframework.net" xmlns:v="http://www.springframework.net/validation">
|
||||
|
||||
<object type="TripForm.aspx" parent="standardPage">
|
||||
<property name="TripValidator" ref="tripValidator" />
|
||||
@@ -255,13 +272,13 @@
|
||||
<para>The condition validator evaluates any logical expression that is
|
||||
supported by Spring's evaluation engine. The syntax is</para>
|
||||
|
||||
<programlisting><v:<emphasis role="bold">condition</emphasis> id="id" test="testCondition" when="applicabilityCondition" parent="parentValidator">
|
||||
<programlisting language="myxml"><v:condition id="id" test="testCondition" when="applicabilityCondition" parent="parentValidator">
|
||||
actions
|
||||
</v:<emphasis role="bold">condition</emphasis>></programlisting>
|
||||
</v:condition></programlisting>
|
||||
|
||||
<para>An example is shown below</para>
|
||||
|
||||
<programlisting><v:condition test="StartingFrom.Date >= DateTime.Today" when="StartingFrom.Date != DateTime.MinValue">
|
||||
<programlisting language="myxml"><v:condition test="StartingFrom.Date >= DateTime.Today" when="StartingFrom.Date != DateTime.MinValue">
|
||||
<v:message id="error.departureDate.inThePast" providers="departureDateErrors, validationSummary"/>
|
||||
</v:condition></programlisting>
|
||||
|
||||
@@ -295,13 +312,13 @@
|
||||
<para>This validator ensures that the specified test value is not empty.
|
||||
The syntax is</para>
|
||||
|
||||
<programlisting><v:<emphasis role="bold">required</emphasis> id="id" test="requiredValue" when="applicabilityCondition" parent="parentValidator">
|
||||
<programlisting language="myxml"><v:required id="id" test="requiredValue" when="applicabilityCondition" parent="parentValidator">
|
||||
actions
|
||||
</v:<emphasis role="bold">required</emphasis>></programlisting>
|
||||
</v:required></programlisting>
|
||||
|
||||
<para>An example is shown below</para>
|
||||
|
||||
<programlisting><v:required test="ReturningFrom.AirportCode">
|
||||
<programlisting language="myxml"><v:required test="ReturningFrom.AirportCode">
|
||||
<v:message id="error.destinationAirport.required" providers="destinationAirportErrors, validationSummary"/>
|
||||
</v:required></programlisting>
|
||||
|
||||
@@ -361,15 +378,15 @@
|
||||
|
||||
<para>The syntax is</para>
|
||||
|
||||
<programlisting><v:<emphasis role="bold">regex</emphasis> id="id" test="valueToEvaluate" when="applicabilityCondition" parent="parentValidator">
|
||||
<<emphasis role="bold">v:property name="Expression" value="regularExpressionToMatch"</emphasis>/>
|
||||
<programlisting language="myxml"><v:regex id="id" test="valueToEvaluate" when="applicabilityCondition" parent="parentValidator">
|
||||
<v:property name="Expression" value="regularExpressionToMatch"/>
|
||||
<v:property name="Options" value="regexOptions"/>
|
||||
actions
|
||||
</v:<emphasis role="bold">regex</emphasis>></programlisting>
|
||||
</v:regex></programlisting>
|
||||
|
||||
<para>An example is shown below</para>
|
||||
|
||||
<programlisting><v:regex test="ReturningFrom.AirportCode">
|
||||
<programlisting language="myxml"><v:regex test="ReturningFrom.AirportCode">
|
||||
<v:property name="Expression" value="[A-Z][A-Z][A-Z]"/>
|
||||
<v:message id="error.destinationAirport.threeCharacters" providers="destinationAirportErrors, validationSummary"/>
|
||||
</v:regex></programlisting>
|
||||
@@ -389,13 +406,13 @@
|
||||
|
||||
<para>The syntax is</para>
|
||||
|
||||
<programlisting><v:<emphasis role="bold">validator</emphasis> id="id" test="requiredValue" when="applicabilityCondition" type="validatorType" parent="parentValidator">
|
||||
<programlisting language="myxml"><v:validator id="id" test="requiredValue" when="applicabilityCondition" type="validatorType" parent="parentValidator">
|
||||
actions
|
||||
</v:<emphasis role="bold">validator</emphasis>></programlisting>
|
||||
</v:validator></programlisting>
|
||||
|
||||
<para>An example is shown below</para>
|
||||
|
||||
<programlisting><v:validator test="ReturningFrom.AirportCode" type="MyNamespace.MyAirportCodeValidator, MyAssembly">
|
||||
<programlisting language="myxml"><v:validator test="ReturningFrom.AirportCode" type="MyNamespace.MyAirportCodeValidator, MyAssembly">
|
||||
<v:message id="error.destinationAirport.invalid" providers="destinationAirportErrors, validationSummary"/>
|
||||
</v:required></programlisting>
|
||||
|
||||
@@ -425,7 +442,7 @@
|
||||
TripMode.RoundTrip enum value. In order to achieve that we created
|
||||
following validator definition:</para>
|
||||
|
||||
<programlisting><v:group id="returnDateValidator" when="Mode == 'RoundTrip'">
|
||||
<programlisting language="myxml"><v:group id="returnDateValidator" when="Mode == 'RoundTrip'">
|
||||
// nested validators
|
||||
</v:group></programlisting>
|
||||
|
||||
@@ -463,13 +480,13 @@
|
||||
|
||||
<para>The syntax is</para>
|
||||
|
||||
<programlisting><v:message id="messageId" providers="errorProviderList" when="messageApplicabilityCondition">
|
||||
<programlisting language="myxml"><v:message id="messageId" providers="errorProviderList" when="messageApplicabilityCondition">
|
||||
<v:param value="paramExpression"/>
|
||||
</v:message></programlisting>
|
||||
|
||||
<para>An example is shown below</para>
|
||||
|
||||
<programlisting><v:message id="error.departureDate.inThePast" providers="departureDateErrors, validationSummary">
|
||||
<programlisting language="myxml"><v:message id="error.departureDate.inThePast" providers="departureDateErrors, validationSummary">
|
||||
<v:param value="StartingFrom.Date.ToString('D')"/>
|
||||
<v:param value="DateTime.Today.ToString('D')"/>
|
||||
</v:message></programlisting>
|
||||
@@ -505,13 +522,13 @@
|
||||
|
||||
<para>The syntax is</para>
|
||||
|
||||
<programlisting><v:action type="actionType" when="actionApplicabilityCondition">
|
||||
<programlisting language="myxml"><v:action type="actionType" when="actionApplicabilityCondition">
|
||||
properties
|
||||
</v:action></programlisting>
|
||||
|
||||
<para>An example is shown below</para>
|
||||
|
||||
<programlisting><v:action type="Spring.Validation.Actions.ExpressionAction, Spring.Core" when="#page != null">
|
||||
<programlisting language="myxml"><v:action type="Spring.Validation.Actions.ExpressionAction, Spring.Core" when="#page != null">
|
||||
<v:property name="Valid" value="#page.myPanel.Visible = true"/>
|
||||
<v:property name="Invalid" value="#page.myPanel.Visible = false"/>
|
||||
</v:action></programlisting>
|
||||
@@ -527,7 +544,7 @@
|
||||
implementation, which is fairly simple thing to do – all you need to do
|
||||
is implement <literal>IValidationAction</literal> interface:</para>
|
||||
|
||||
<programlisting>public interface IValidationAction
|
||||
<programlisting language="csharp">public interface IValidationAction
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the action.
|
||||
@@ -554,11 +571,11 @@
|
||||
|
||||
<para>The syntax is shown below</para>
|
||||
|
||||
<programlisting><v:ref name="referencedValidatorId" context="validationContextForTheReferencedValidator"/></programlisting>
|
||||
<programlisting language="myxml"><v:ref name="referencedValidatorId" context="validationContextForTheReferencedValidator"/></programlisting>
|
||||
|
||||
<para>An example is shown below</para>
|
||||
|
||||
<programlisting><v:group id="objectA.validator">
|
||||
<programlisting language="myxml"><v:group id="objectA.validator">
|
||||
<v:ref name="objectC.validator" context="MyObjectC"/>
|
||||
// other validators for ObjectA
|
||||
</v:group>
|
||||
@@ -588,7 +605,7 @@
|
||||
<para>You can also create Validators programmatically using the API. An
|
||||
example is shown below</para>
|
||||
|
||||
<programlisting>UserInfo userInfo = new UserInfo(); // has Name and Password props
|
||||
<programlisting language="csharp">UserInfo userInfo = new UserInfo(); // has Name and Password props
|
||||
|
||||
ValidatorGroup userInfoValidator = new ValidatorGroup();
|
||||
|
||||
@@ -610,7 +627,7 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
useful for performing server-side validation.</para>
|
||||
</section>
|
||||
|
||||
<section id="validation-aspnet-usage">
|
||||
<section xml:id="validation-aspnet-usage">
|
||||
<title>Usage tips within ASP.NET</title>
|
||||
|
||||
<para>Now that you know how to configure validation rules, let's see what
|
||||
@@ -620,7 +637,7 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
<para>The first thing you need to do is inject validators you want to use
|
||||
into your ASP.NET page, as shown in the example below:</para>
|
||||
|
||||
<programlisting><objects xmlns="http://www.springframework.net" xmlns:v="http://www.springframework.net/validation">
|
||||
<programlisting language="myxml"><objects xmlns="http://www.springframework.net" xmlns:v="http://www.springframework.net/validation">
|
||||
|
||||
<object type="TripForm.aspx" parent="standardPage">
|
||||
<property name="TripValidator" ref="tripValidator" />
|
||||
@@ -635,7 +652,7 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
<para>Once that's done, you need to perform validation in one or more of
|
||||
the page event handlers, which typically looks similar to this:</para>
|
||||
|
||||
<programlisting>public void SearchForFlights(object sender, EventArgs e)
|
||||
<programlisting language="csharp">public void SearchForFlights(object sender, EventArgs e)
|
||||
{
|
||||
if (Validate(Controller.Trip, tripValidator))
|
||||
{
|
||||
@@ -654,7 +671,7 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
<literal><spring:validationSummary/></literal> controls to the
|
||||
ASP.NET form:</para>
|
||||
|
||||
<programlisting><%@ Page Language="c#" MasterPageFile="~/Web/StandardTemplate.master" Inherits="TripForm" CodeFile="TripForm.aspx.cs" %>
|
||||
<programlisting language="myxml"><%@ Page Language="c#" MasterPageFile="~/Web/StandardTemplate.master" Inherits="TripForm" CodeFile="TripForm.aspx.cs" %>
|
||||
<%@ Register TagPrefix="spring" Namespace="Spring.Web.UI.Controls" Assembly="Spring.Web" %>
|
||||
|
||||
<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">
|
||||
@@ -674,7 +691,7 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
<asp:Content ID="body" ContentPlaceHolderID="body" runat="server">
|
||||
<div style="text-align: center">
|
||||
<h4><asp:Label ID="caption" runat="server"></asp:Label></h4>
|
||||
<emphasis role="bold"><spring:ValidationSummary ID="validationSummary" runat="server" /></emphasis>
|
||||
<spring:ValidationSummary ID="validationSummary" runat="server" />
|
||||
<table>
|
||||
<tr class="formLabel">
|
||||
<td>&nbsp;</td>
|
||||
@@ -690,13 +707,13 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
<asp:Label ID="leavingFrom" runat="server" /></td>
|
||||
<td nowrap="nowrap">
|
||||
<asp:DropDownList ID="leavingFromAirportCode" AutoCallBack="true" runat="server" />
|
||||
<emphasis role="bold"><spring:ValidationError id="departureAirportErrors" runat="server" /></emphasis>
|
||||
<spring:ValidationError id="departureAirportErrors" runat="server" />
|
||||
</td>
|
||||
<td class="formLabel" align="right">
|
||||
<asp:Label ID="goingTo" runat="server" /></td>
|
||||
<td nowrap="nowrap">
|
||||
<asp:DropDownList ID="goingToAirportCode" AutoCallBack="true" runat="server" />
|
||||
<emphasis role="bold"><spring:ValidationError id="destinationAirportErrors" runat="server" /></emphasis>
|
||||
<spring:ValidationError id="destinationAirportErrors" runat="server" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -704,14 +721,14 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
<asp:Label ID="leavingOn" runat="server" /></td>
|
||||
<td nowrap="nowrap">
|
||||
<spring:Calendar ID="leavingFromDate" runat="server" Width="75px" AllowEditing="true" Skin="system" />
|
||||
<emphasis role="bold"><spring:ValidationError id="departureDateErrors" runat="server" /></emphasis>
|
||||
<spring:ValidationError id="departureDateErrors" runat="server" />
|
||||
</td>
|
||||
<td class="formLabel" align="right">
|
||||
<asp:Label ID="returningOn" runat="server" /></td>
|
||||
<td nowrap="nowrap">
|
||||
<div id="returningOnCalendar">
|
||||
<spring:Calendar ID="returningOnDate" runat="server" Width="75px" AllowEditing="true" Skin="system" />
|
||||
<emphasis role="bold"><spring:ValidationError id="returnDateErrors" runat="server" /></emphasis>
|
||||
<spring:ValidationError id="returnDateErrors" runat="server" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -805,7 +822,7 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
<literal>Spring.Web.Validation.IValidationErrorsRenderer</literal>
|
||||
interface:</para>
|
||||
|
||||
<programlisting>namespace Spring.Web.Validation
|
||||
<programlisting language="csharp">namespace Spring.Web.Validation
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface should be implemented by all validation errors renderers.
|
||||
@@ -842,7 +859,7 @@ bool userInfoIsValid = userInfoValidator.Validate(userInfo, errors);
|
||||
templates for <literal><spring:validationSummary></literal> and
|
||||
<literal><spring:validationError></literal> controls:</para>
|
||||
|
||||
<programlisting><!-- Validation errors renderer configuration -->
|
||||
<programlisting language="myxml"><!-- Validation errors renderer configuration -->
|
||||
<object id="Spring.Web.UI.Controls.ValidationError" abstract="true">
|
||||
<property name="Renderer">
|
||||
<object type="Spring.Web.Validation.IconValidationErrorsRenderer, Spring.Web">
|
||||
|
||||
Reference in New Issue
Block a user