Update of /cvsroot/springnet/Spring.Net/doc/reference/src
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv14413
Modified Files:
aop-aspect-library.xml validation.xml
Log Message:
SPRNET-911 - Provide ParameterValidationAdvice to use validation framework to validate method arguments.
Index: validation.xml
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/doc/reference/src/validation.xml,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** validation.xml 25 Feb 2008 20:35:59 -0000 1.20
--- validation.xml 2 Apr 2008 22:59:54 -0000 1.21
***************
*** 583,587 ****
</section>
! <section>
<title>Usage tips within ASP.NET</title>
--- 583,587 ----
</section>
! <section id="validation-aspnet-usage">
<title>Usage tips within ASP.NET</title>
Index: aop-aspect-library.xml
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/doc/reference/src/aop-aspect-library.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** aop-aspect-library.xml 16 Jan 2008 17:21:44 -0000 1.11
--- aop-aspect-library.xml 2 Apr 2008 22:59:54 -0000 1.12
***************
*** 10,16 ****
module. However, the aspects that are documented in this section are those
contained within the Spring.Aop module itself. The aspects in within
! Spring.Aop.dll are Caching, Exception Handling, Logging, and Retry. Other
! traditional advice types such as validation, security, and thread
! management, will be included in a future release.</para>
</sect1>
--- 10,17 ----
module. However, the aspects that are documented in this section are those
contained within the Spring.Aop module itself. The aspects in within
! Spring.Aop.dll are Caching, Exception Handling, Logging, Retry, and
! Parameter Validation. Other traditional advice types such as validation,
! security, and thread management, will be included in a future
! release.</para>
</sect1>
***************
*** 657,659 ****
--- 658,727 ----
<link linkend="transaction">transaction management</link>.</para>
</sect1>
+
+ <sect1>
+ <title>Parameter Validation</title>
+
+ <para>Spring provides a UI-agnostic <link linkend="validation">validation
+ framework</link> in which you can declare validation rules, both
+ progammatically and declaratively, and have those rules evaluated against
+ an arbitrary .NET object. Spring provides additional support for rendering
+ of validation errors within Spring's ASP.NET framework. (See the section
+ on <link linkend="validation-aspnet-usage" os="">ASP.NET usage tips</link>
+ for more information.) However, validation is not confined to the UI tier.
+ It is a common task that occurs across most, if not all, applications
+ layers. Validation that is performed in the UI layer is often repeated in
+ the service layer, in order to be proactive in case non UI-based clients
+ invoke the service layer. Validation rules completely different from those
+ used in the UI layer may be used on the server side. </para>
+
+ <para>To address some of the common needs for validation on the server
+ side, Spring provides parameter validation advice so that applies Spring's
+ validation rules to the method parameters. The class
+ <classname>ParameterValidationAdvice</classname> is used in conjunction
+ with the <classname>Validated</classname> attribute to specify which
+ validation rules are applied to method parameters. For example, to apply
+ parameter validation to the method SuggestFlights in the BookingAgent
+ class used in the <link linkend="springair">SpringAir sample
+ application</link>, you would apply the <classname>Validated</classname>
+ attribute to the method parameters as shown below.</para>
+
+ <programlisting>public FlightSuggestions SuggestFlights( [Validated("tripValidator")] Trip trip)
+ {
+ // unmodified implementation goes here
+ }</programlisting>
+
+ <para>The <literal>Validated</literal> attribute takes a string name that
+ specifies the name of the validation rule, i.e. the name of the IValidator
+ object in the Spring application context. The
+ <classname>Validated</classname> attribute is located in the namespace
+ <literal>Spring.Validation</literal> of the <literal>Spring.Core</literal>
+ assembly.</para>
+
+ <para>The configuration of the advice is to simply define the an instance
+ of the <literal>ParameterValidationAdvice</literal> class and apply the
+ advice, for example based on object names using an
+ <classname>ObjectNameAutoProxyCreator</classname>, as shown below,</para>
+
+ <programlisting> <object id="<emphasis role="bold">validationAdvice</emphasis>" type="Spring.Aspects.Validation.ParameterValidationAdvice, Spring.Aop"/>
+
+ <object type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
+ <property name="ObjectNames">
+ <list>
+ <value>bookingAgent</value>
+ </list>
+ </property>
+ <property name="InterceptorNames">
+ <list>
+ <value><emphasis role="bold">validationAdvice</emphasis></value>
+ </list>
+ </property>
+ </object></programlisting>
+
+ <para>When the advised method is invoked first the validation of each
+ method parameter is performed. If all validation succeeds, then the method
+ body is executed. If validation fails an exception of the type
+ <classname>ValidationException</classname> is thrown and you can retrieve
+ errors information from its property <literal>ValidationErrors</literal>.
+ See the SDK documentation for details. </para>
+ </sect1>
</chapter>
\ No newline at end of file
|