blob: f4248e4f0ae24fe3b205eb73ed5b6b939f5fa069 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
-->
<ui:composition template="/main.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:tc="http://myfaces.apache.org/tobago/component"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<p>There are several ways to validate the content of a component. In general input components have the option
for validation. In the following sections, the different kinds von validation are explained.</p>
<p>Tag Library Documentation:
<tc:link label="&lt;tc:sheet/>" image="#{request.contextPath}/image/feather-leaf.png"
link="#{apiController.tldBase}/#{apiController.currentRelease}/tld/tc/sheet.html"/>
|
<tc:link label="&lt;tc:column/>" image="#{request.contextPath}/image/feather-leaf.png"
link="#{apiController.tldBase}/#{apiController.currentRelease}/tld/tc/column.html"/></p>
<tc:section label="Required">
<p>A simple way of validation is the <code>required</code> attribute in some input components.
The text area must not empty if the submit button is pressed. Otherwise a error message is displayed.</p>
<demo-highlight language="markup">&lt;tc:textarea label="Text Area" required="true"/></demo-highlight>
<tc:form id="required">
<tc:textarea id="textarea" label="Text Area" required="true"/>
<tc:button id="submit_r" label="Submit"/>
</tc:form>
</tc:section>
<tc:section label="Validate Length">
<p>The length of a value can be validated by the <code class="language-markup">&lt;f:validateLength/></code> tag.
Length means the number of characters.
In this example, the given string must have at least two characters and maximal four characters.</p>
<p>Please note, an empty string will not be validated.</p>
<demo-highlight language="markup">&lt;tc:in label="Input">
&lt;f:validateLength minimum="2" maximum="4"/>
&lt;/tc:in></demo-highlight>
<tc:form id="validateLength">
<tc:in id="in_vl" label="Text">
<f:validateLength minimum="2" maximum="4"/>
</tc:in>
<tc:button id="submit_vl" label="Submit"/>
</tc:form>
</tc:section>
<tc:section label="Validate Range">
<p>The range of a number can be validated via <code class="language-markup">&lt;f:validateLongRange/></code>
or - for floating point numbers - <code class="language-markup">&lt;f:validateDoubleRange/></code>.
In the following input field numbers from 3 to 77 can be added.</p>
<demo-highlight language="markup">&lt;tc:in label="Number" markup="number">
&lt;f:validateLongRange minimum="3" maximum="77"/>
&lt;/tc:in></demo-highlight>
<tc:form id="validateRange">
<tc:in id="in_vr" label="Number" markup="number">
<f:validateLongRange minimum="3" maximum="77"/>
</tc:in>
<tc:button id="submit_vr" label="Submit"/>
</tc:form>
</tc:section>
<tc:section label="Regex Validation">
<p>A value can be validated against a regex patter via the
<code class="language-markup">&lt;f:validateRegex/></code> tag.</p>
<demo-highlight language="markup">&lt;tc:in label="Letter &amp; Number" >
&lt;f:validateRegex pattern="[A-Za-z][0-9]"/>
&lt;/tc:in></demo-highlight>
<tc:form id="regexValidation">
<p>The value in the field must be a word character combined with a number. For example 'T3'.</p>
<tc:in id="in_rv" label="Letter &amp; Number" value="#{validationController.letter}">
<f:validateRegex pattern="[A-Za-z][0-9]"/>
</tc:in>
<tc:button id="submit_rv" label="Submit"/>
</tc:form>
</tc:section>
<tc:section label="Custom Validator">
<p>It's also possible to add custom validators using the <code>validator</code> attribute of an input component.
In this case, only the string 'Tobago' (uppercase/lowercase ignored) is accepted.</p>
<tc:form id="customValidator">
<tc:in id="in_cv" label="Text" validator="#{validationController.customValidator}"/>
<tc:button id="submit_cv" label="Submit"/>
</tc:form>
</tc:section>
<tc:section label="Two Field Validation">
<p>A validator check the password against the confirmation field.
To get access to the confirmation field from the validator a binding with the <code>binding</code> attribute
and the <code class="language-markup">&lt;f:attribute/></code> tag is created.</p>
<demo-highlight language="markup">&lt;tc:in label="Password" validator="\#{validationController.passwordValidator}">
&lt;f:attribute name="confirmationField" value="\#{confirmBinding}"/>
&lt;/tc:in>
&lt;tc:in label="Confirmation" binding="\#{confirmBinding}"/></demo-highlight>
<tc:form>
<tc:in label="Password" required="true" validator="#{validationController.passwordValidator}">
<f:attribute name="confirmationField" value="#{confirmBinding}"/>
</tc:in>
<tc:in label="Confirmation" required="true" binding="#{confirmBinding}"/>
<tc:button label="Submit"/>
</tc:form>
</tc:section>
</ui:composition>