home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!--
- Copyright 1999-2004 The Apache Software Foundation
-
- 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.
- -->
-
- <xsp:page language="java"
- xmlns:xsp="http://apache.org/xsp"
- xmlns:xsp-formval="http://apache.org/xsp/form-validator/2.0"
- xmlns:xsp-request="http://apache.org/xsp/request/2.0">
-
- <page>
-
- <resources>
- <resource type="file" href="descriptor.xml?cocoon-view=pretty-content">Descriptor</resource>
- <resource type="doc" href="userdocs/xsp/logicsheet-forms.html">Action & Logicsheet</resource>
- </resources>
-
- <title>Car Reservation</title>
- <content>
-
- <para>
- Informal validation results <xsp:expr><xsp-formval:results/></xsp:expr>
- </para>
-
- <form method="POST">
- <!-- use this to get a clue if the user had a chance to fill in
- any date already. This is necessary if no validation results should be
- displayed when the user first encounters the form. If the error messages
- should be used to guide the user from the beginning, this is not needed.
- -->
- <input type="hidden" name="visited" value="true"/>
- <xsp:logic>
- boolean userHasSeenForm = (<xsp-request:get-parameter name="visited"/>!=null);
- </xsp:logic>
-
-
-
- <!-- if validation constraints should be included in the error messages, a
- reference to the file containing the validation rules is needed. Otherwise
- it can be removed.
- -->
- <xsp-formval:descriptor name="descriptor.xml" constraint-set="car-reservation">
-
- <table>
- <tbody>
-
- <!-- the first example field illustrates the simplest usage, passing the current
- validation field name every time.
- -->
- <tr>
- <td>How many persons should the car seat?</td>
- <td>
- <input type="TEXT" name="persons" size="2">
- <xsp:attribute name="value"><xsp-request:get-parameter name="persons" default=""/></xsp:attribute>
- </input>
- </td>
- <td>
- <xsp:logic>
- if (userHasSeenForm) {
- if (<xsp-formval:is-toosmall name="persons"/> ) {
- <b> The smallest available car seats <xsp-formval:get-attribute parameter="persons" name="min"/></b>
- } else if ( <xsp-formval:is-toolarge name="persons"/> ) {
- <b> The largest available car seats <xsp-formval:get-attribute parameter="persons" name="max"/></b>
- } else if (<xsp-formval:is-error name="persons"/> ) {
- <b> Some error occured. Your input is not correct. </b>
- }
- }
- </xsp:logic>
- </td>
- </tr>
-
-
- <!-- another possibility is to create a context that is used for all nested
- validation tags. Note that here no validation parameter name is added to
- the validation tags.
- -->
- <xsp-formval:validate name="deposit">
- <tr>
- <td>Please enter your deposit EUR</td>
- <td>
- <input type="TEXT" name="deposit" size="10">
- <xsp:attribute name="value"><xsp-request:get-parameter name="deposit" default=""/></xsp:attribute>
- </input>
- </td>
- <td>
- <xsp:logic>
- if (userHasSeenForm) {
- if ( <xsp-formval:is-null/>) {
- <b> You need to specify a deposit </b>
- } else if ( <xsp-formval:is-toosmall/> ) {
- <b> The deposit has to be at least EUR <xsp-formval:get-attribute name="min"/></b>
- } else if ( <xsp-formval:is-toolarge/> ) {
- <b> The deposit has to be at most EUR <xsp-formval:get-attribute name="max"/></b>
- } else if (<xsp-formval:is-notpresent/> ) {
- <b></b>
- } else if ( <xsp-formval:is-error/>) {
- <b> Some error occured. Your input is not correct. </b>
- }
- }
- </xsp:logic>
- </td>
- </tr>
- </xsp-formval:validate>
-
- <xsp-formval:validate name="email">
- <tr>
- <td>Please enter your email</td>
- <td>
- <input type="TEXT" name="email" size="50">
- <xsp:attribute name="value"><xsp-request:get-parameter name="email" default=""/></xsp:attribute>
- </input>
- </td>
- <td>
- <xsp:logic>
- if (userHasSeenForm) {
- if ( <xsp-formval:is-null/>) {
- <b> You need to specify an email </b>
- } else if ( <xsp-formval:is-nomatch/> ) {
- <b> This does not seem to be a valid email
- address. Expected
- <pre><xsp-formval:get-attribute parameter="email" name="matches-regex"/></pre>
- </b>
- } else if ( <xsp-formval:is-toolarge/> ) {
- <b> Only addresses with up to
- <xsp-formval:get-attribute parameter="email" name="max-len"/>
- characters are accepted
- </b>
- } else if (<xsp-formval:is-notpresent/> ) {
- <b></b>
- } else if ( <xsp-formval:is-error/>) {
- <b> Some error occured. Your input is not correct. </b>
- }
- }
- </xsp:logic>
- </td>
- </tr>
- </xsp-formval:validate>
-
-
- <!-- less embedded java is needed when using the <xsp-formval:on-XXX/> tags. They are
- equivalent to the above "<xsp:logic>if (<xsp-formval:is-XXX/>) { ... } </xsp:logic>"
- but much cleaner.
- -->
- <xsp-formval:validate name="address">
- <tr>
- <td>Please enter the billing address</td>
- <td>
- <textarea rows="6" cols="40" name="address"><xsp-request:get-parameter name="address" default=""/></textarea>
- </td>
- <td>
- <xsp:logic>
- if (userHasSeenForm) {
- <xsp-formval:on-null>
- <b> You need to specify an address. </b>
- </xsp-formval:on-null>
-
- <xsp-formval:on-toolarge>
- <b> Only addresses with up to
- <xsp-formval:get-attribute parameter="address" name="max-len"/>
- characters are accepted.
- </b>
- </xsp-formval:on-toolarge>
-
- <xsp-formval:on-notpresent/>
-
- <xsp-formval:on-error>
- <b> Some error occured. Your input is not correct. </b>
- </xsp-formval:on-error>
- }
- </xsp:logic>
- </td>
- </tr>
- </xsp-formval:validate>
-
-
- <xsp-formval:validate name="type">
- <tr>
- <td>Please enter the type of car you would like to reserve</td>
- <td>
- <input type="text" name="type" size="10">
- <xsp:attribute name="value"><xsp-request:get-parameter name="type" default=""/></xsp:attribute>
- </input>
- </td>
- <td>
- <xsp:logic>
- if (userHasSeenForm) {
- <xsp-formval:on-null>
- <b> You need to specify a type: cabrio, sedan, station, racing. </b>
- </xsp-formval:on-null>
-
- <xsp-formval:on-nomatch>
- <b> Only <xsp-formval:get-attribute parameter="type" name="one-of"/>
- are accepted.
- </b>
- </xsp-formval:on-nomatch>
-
- <xsp-formval:on-notpresent/>
-
- <xsp-formval:on-error>
- <b> Some error occured. Your input is not correct. </b>
- </xsp-formval:on-error>
- }
- </xsp:logic>
- </td>
- </tr>
- </xsp-formval:validate>
- </tbody>
- </table>
-
- </xsp-formval:descriptor>
- <input type="submit" name="submit" value="submit"/>
- </form>
-
- </content>
- </page>
- </xsp:page>
-