Predefined Validators

The Calyxo Forms component contains predefined validators (i.e., matchers, converters and checkers), which are suitable for various standard tasks arising in the context of input validation. Among others, there are matchers, which trim the input or match it against a regular expression, converters for all of the standard data types, and checkers for string length validation or numerical ranges.

Since the configuration file containing the declarations of the predefined validators is contained in the Calyxo Forms jar file, all of them are already available to applications. For documentation purposes, a copy is located in CALYXO_HOME/calyxo-forms/conf/share/calyxo-validators.xml.

In the same directory you can find a copy of the default messages contained in the file calyxo-validators.properties. All validators, which can fail, have a predefined error message to be found in this file. Every predefined error message takes an argument used to identify the input field which caused the error. It is named field in all validator message declarations. A message belonging to a validator with one or more properties may have additional unnamed arguments, which are set to current property values of the validator, to make the message more precise. However, these message arguments cannot be overridden.

Therefore, using a predefined validator typically means to supply the message argument named field as in

<check name="less">
  <message>
    <arg name="field" .../>
  </message>
</check>

See the section on Messages on how argument values are specified.

If you intend to use a different message bundle, e.g. myBundle, you have two options:

  1. To use your own bundle for all predefined validator messages, invoke setBundleAlias("calyxo-forms-validators", "myBundle") on the module's I18nSupport instance. There's a convenient way to do this in your configuration file:
    <calyxo-forms-config version="0.9"
      xmlns:base="http://calyxo.odysseus.de/xml/ns/base"
      xmlns="http://calyxo.odysseus.de/xml/ns/forms">
      ...
      <base:use>
        <base:member class="de.odysseus.calyxo.base.I18nSupport">
          <base:method name="getInstance">
            <base:arg value="${moduleContext}"/>
          </base:method>
        </base:member>
        <base:method name="setBundleAlias">
          <base:arg value="calyxo-forms-validators"/>
          <base:arg value="myBundle"/>
        </base:method>
      </base:use>
      ...
    </calyxo-forms-config>
    
  2. To use a different bundle in a single validation, override the bundle attribute in the message element.
    <convert name="date">
      <message bundle="myBundle">
        <arg name="field" .../>
      </message>
    </convert>
    

To replace the whole message, specify both the bundle and key attribute in the message element. For example, this may be desired when using the regexp matcher, which produces a rather generic message including the the regular expression pattern:

<match name="regexp">
  <property name="pattern" value="..."/>
  <message bundle="myBundle" key="myKey">
    ...
  </message>
</check>

On the following pages you can find an overview describing all the predefined validators from the Calyxo Forms component.