Annotated example-form.xml

Author: Anthony Eden

The following configuration is taken from the example application which ships with the FormProc distribution.


<?xml version="1.0" encoding="ISO-8859-1"?>

This is required at the begining of every XML document. You can change the encoding value if you need to include foreign characters in your configuration.


Signifies the start of a form configuration.


The name of the form. This name is used to distinguish this form from other forms.

	<storer classname=""/>

Define a default storer to be used throughout the form. FormProc supports automatic population of target objects using the ReflectionStorer class. The store system is pluggable. The storer class can be any class which implements the interface or extends from the abstract base class. FormProc currently ships with two storers: the ReflectionStorer and the MapStorer which stores values in a map of key/value pairs.

	<element name="name">

The first element definition. Each form element must be defined here.

		<validator type="shared" name="required">
			<error>Name field required.</error>
			<error lang="fr">Le nom valide a exigé.</error>

Define the validator which is used for the FormElement. This particular configuration sets the validator to the shared validator "required" which is defined in the formproc.xml configuration. It also overrides the error messages of the shared validator. Note that error elements can include a lang attribute which specifies the language of the error message. The lang attribute must be a two-character ISO language code as defined in the java.util.Locale class. If no lang attribute is specified then that error message will be used as the default in case an error message for a specific language is unspecified.


Specifies the write method used by the reflection storer.


A message which can be displayed to the user. The message element can include a lang attribute which specifies the message language. The lang attribute requires a two-character ISO language code as defined in the java.util.Locale class. If no lang attribute is specified then that message will be used as the default in case a message for a specific language is unspecified.


Close the "name" element's configuration.

	<element name="occupation" optional="true">

Configure a second form element which is similar to the "name" element. This element is for an "occupation" field. The optional="true" attribute makes this element optional. Optional elements will not be validated, converted or stored if their value is null or an empty String.

		<default>Not Defined</default>

Defines the default value which is used if the submitted value is either null or an empty String.


Specify a message which can be displayed to the user and close the "occupation" form element's configuration.

	<element name="username">
		<validator type="shared" name="username"/>
		<message resource="org.formproc.example.ExampleResourceBundle">username.message</message>

This form element definition is uses a shared validator called "username". In addition, it defines a resource bundle and the resource key which is used for determining error messages when validation fails.

	<element name="age" optional="true">
		<validator type="shared" name="age"/>
		<message>Optional.  If specified, a valid age required.</message>
		<message lang="fr">Optional. L'âge valide a exigé.</message>
		<converter classname="org.formproc.conversion.IntegerConverter"/>

Optional age field. This form element defines a converter which is used to convert the incoming data. Conversion occurs after validation but prior to storing. FormProc comes with a set of standard converters which can easily be augmented by creating new converter classes which implement the org.formproc.conversion.TypeConverter interface or extend from the org.formproc.conversion.AbstractTypeConverter abstract base class.

	<element name="birthdate">
		<validator type="expression">
			<error>Date must be in format MM/dd/yyyy</error>
		<message lang="en">Valid date (MM/dd/yyyy) required.</message>
		<message lang="fr">Le date valide (MM/dd/yyyy) a exigé.</message>
		<converter classname="org.formproc.conversion.DateConverter">
			<parse type="custom" pattern="MM/dd/yyyy"/>

This element definition defines the validator here rather than using a shared validator. It also defines locale-specific messages as well as a custom converter. Notice that converters can have configuration data specified as well. When the converter is created the TypeConverter.loadConfiguration(Configuration configuration) method is called with a configuration tree representing the elements and attributes which are children of the converter element.

	<element name="password">
		<validator type="shared" name="password"/>
		<message classname="org.formproc.message.ResourceBundleMessageProvider">

This element uses a shared validator called "password". It also defines a custom MessageProvider for returning message values. Any class can be used in the message element's classname attribute as long as it implements the org.formproc.message.MessageProvider interface. In this case the custom provider provides the same implementation as the message tag in the "username" element definition.

	<element name="passwordVerify">
		<validator type="shared" name="password"/>
		<message resource="org.formproc.example.ExampleResourceBundle">passwordVerify.message</message>

The final element definition is another example of using a resource bundle and resource key to provide localized messages.

	<element-group name="password">
		<element name="password"/>
		<element name="passwordVerify"/>
		<validator type="script">
			<error lang="en">Passwords must must match.</error>
			<error lang="fr">La nécessité de mots de passe doit s'assortir.</error>

This element defines an element group. The element group will execute the specified validator and will provide all of the submitted data for the specified elements. The element group is designed to allow comparison of multiple elements with each other.


Close the form configuration.