[cvs] expresso/expresso-web/expresso/doc/edg validation.xml
JCorporate Ltd
jcorp at jcorp2.servlets.net
Wed Aug 11 13:22:16 PDT 2004
Update of /home/javacorp/.cvs/expresso/expresso/expresso-web/expresso/doc/edg
In directory jcorp2.servlets.net:/tmp/cvs-serv20467
Modified Files:
validation.xml
Log Message:
<Aucun commentaire entré>
Index: validation.xml
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/expresso/doc/edg/validation.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** validation.xml 9 Aug 2004 16:30:27 -0000 1.1
--- validation.xml 11 Aug 2004 20:22:13 -0000 1.2
***************
*** 247,275 ****
<programlisting> <field property="customeremail" depends="email">
<arg0 key="customer.email"/>
! </field></programlisting> url - validates url format. Has four
! optional variables (allowallschemes, allow2slashes, nofragments and
! schemes) which can be used to configure this validator. allowallschemes
! specifies whether all schemes are allowed. Valid values are true or false
! (default is false). If this is set to true then the schemes variable is
! ignored. allow2slashes specifies whether double '/' characters are
! allowed. Valid values are true or false (default is false). nofragments
! specifies whether fragements are allowed. Valid values are true or false
! (default is false - i.e. fragments are allowed). schemes - use to specify
! a comma separated list of valid schemes. If not specified then the
! defaults are used which are http, https and ftp. <programlisting> <field property="custUrl" depends="url">
! <arg0 key="customer.url"/>
! </field>
!
! <field property="custUrl" depends="url">
! <arg0 key="customer.url"/>
! <var>
! <var-name>nofragments</var-name>
! <var-value>true</var-value>
! </var>
! <var>
! <var-name>schemes</var-name>
! <var-value>http,https,telnet,file</var-value>
! </var>
! </field></programlisting> </para>
</sect1>
--- 247,251 ----
<programlisting> <field property="customeremail" depends="email">
<arg0 key="customer.email"/>
! </field></programlisting></para>
</sect1>
***************
*** 364,464 ****
Now youâll form will be validated following the rules you defined in
validation.xml both, client-side and server-side</para>
- </sect1>
-
- <sect1>
- <title>Designing Complex Validations with valid when</title>
-
- <para>[Since Struts 1.2.0] A frequent requirement in validation design is
- to validate one field against another (for example, if you have asked the
- user to type in a password twice for confirmation, to make sure that the
- values match.) In addition, there are fields in a form that may only be
- required if other fields have certain values. The validwhen validation
- rule is designed to handle these cases. The validwhen rule takes a single
- var field, called test. The value of this var is a boolean expression
- which must be true in order for the validation to success. The values
- which are allowed in the expression are:<itemizedlist>
- <listitem>
- <para>Single or double-quoted string literals. </para>
- </listitem>
-
- <listitem>
- <para>Integer literals in decimal, hex or octal format </para>
- </listitem>
-
- <listitem>
- <para>The value null which will match against either null or an
- empty string </para>
- </listitem>
-
- <listitem>
- <para>Other fields in the form referenced by field name, such as
- customerAge</para>
- </listitem>
-
- <listitem>
- <para>Indexed fields in the form referenced by an explicit integer,
- such as childLastName[2] </para>
- </listitem>
-
- <listitem>
- <para>Indexed fields in the form referenced by an implicit integer,
- such as childLastName[], which will use the same index into the
- array as the index of the field being tested. </para>
- </listitem>
-
- <listitem>
- <para>Properties of an indexed fields in the form referenced by an
- explicit or implicit integer, such as child[].lastName, which will
- use the same index into the array as the index of the field being
- tested. </para>
- </listitem>
-
- <listitem>
- <para>The literal *this, which contains the value of the field
- currently being tested</para>
- </listitem>
- </itemizedlist></para>
-
- <para>As an example of how this would work, consider a form with fields
- sendNewsletter and emailAddress. The emailAddress field is only required
- if the sendNewsletter field is not null. You could code this using the
- validwhen rule as: <programlisting> <field depends="validwhen" property="emailAddress">
- <arg0 key="userinfo.emailAddress.label" />
- <var>
- <var-name>test</var-name>
- <var-value>((sendNewsletter == null) or (*this* != null))</var-value>
- </var>
- </field></programlisting>Which reads as: this field is valid if
- sendNewsletter is null or the field value is not null. </para>
-
- <para></para>
-
- <para>Here's a slightly more complicated example using indexed fields.
- Assume a form with a number of lines to allow the user to enter part
- numbers and quantities they wish to order. An array of beans of class
- orderLine is used to hold the entries in a property called orderLines. If
- you wished to verify that every line with part number also had a quantity
- entered, you could do it with:<programlisting> <field depends="validwhen" indexedListProperty="orderLines" property="quantity">
- <arg0 key="orderform.quantity.label" />
- <var>
- <var-name>test</var-name>
- <var-value>((orderLines[].partNumber == null) or (*this* != null))</var-value>
- </var>
- </field></programlisting>Which reads as: This field is value if the
- corresponding partNumber field is null, or this field is not null. </para>
-
- <para> As a final example, imagine a form where the user must enter their
- height in inches, and if they are under 60 inches in height, it is an
- error to have checked off nbaPointGuard as a career. <programlisting> <field depends="validwhen" property="nbaPointGuard">
- <arg0 key="careers.nbaPointGuard.label" />
- <var>
- <var-name>test</var-name>
- <var-value>((heightInInches &gt;= 60) or (*this* == null))</var-value>
- </var>
- </field></programlisting> <emphasis>A few quick notes on the grammer.
- All comparisons must be enclosed in parens. Only two items may be joined
- with and or or If both items to be compared are convertable to ints, a
- numeric comparison is done, otherwise a string comparison is done.
- </emphasis></para>
</sect1>
--- 340,343 ----
More information about the cvs
mailing list