jReform Features

Input Types

jReform supports all types of HTML input controls. Each input class has its own validation rules and slightly different behaviour. All input types with the exception of a single value checkbox can be specified as either required or optional. A single value checkbox cannot be specified as a required input because when unchecked, nothing is submitted with the request and its value is null.

Checkbox, select and radio inputs have a state associated with them that indicates whether the input is checked or selected. This allows the form to maintain its state in cases when validation fails.

Inputs also have support for error messages that can be displayed to the user when submitted values are not valid. Default error messages can be overridden with custom messages where necessary.

Input Type jReform Type
text/textarea/hidden org.jreform.Input
select org.jreform.Select
multi value select org.jreform.MultiSelect
checkbox org.jreform.Checkbox
multi value checkbox org.jreform.MultiCheckbox
radio button org.jreform.Radio

Input Data Types

InputDataType is the Java type of an input's value and it is specified when the input is created. All values submitted through the form are automatically converted into specified data types. When conversion fails the form is deemed invalid.

A few common types are supported out of the box, although the framework can be easily extended to define new types as required.

Input Data Type Java Type
StringType java.lang.String
IntType java.lang.Integer
DoubleType java.lang.Double
FloatType java.lang.Float
LongType java.lang.Long
ShortType java.lang.Short
CharType java.lang.Character
DateType java.util.Date


Criteria provide a simple way to place certain restrictions on input values. If an input does not meet all of its criteria, it is deemed invalid and form validation fails. An example of a typical criterion is a string length requirement, or a range of acceptable values for a number. Note that not all criteria are applicable to all data types. For example, if a numeric range restriction is placed on a string input, an exception will be thrown at runtime.

The following table provides a brief summary of main criteria types. It is also possible to define custom criteria.

Criterion Description
And, Or Allows perform logical operations on two or more criteria.
Email String conforms to email address format.
Min, Max Input is not below/above the Min/Max value.
ExactLength String length must equal given length value.
Length(min, max) String length must be within the given range.
MinLength / MaxLength String length must not be less/greater than MinLength/MaxLength.
Range(min, max) Input value must be within the given range. Equivalent to Min(min) && Max(max).
Regex String must match the specified regular expression.
StartsWith String must start with given value.
StringValues String must equal one of the specified values (allows ignoreCase)
Accept Same as AcceptString but applicable to any java.lang.Comparable

A few examples of using criteria

Password field must be at least 6 characters long

input(stringType(), "password", minLength(6));

Quantity is an integer whose value must be greater than or equal to 1

input(intType(), "quantity", min(1));

Call-back date must be of the format dd-mm-yyyy and must not be a past date

input(dateType("dd-MM-yyyy"), "callBack", min(new Date()));

Custom criteria

A custom criterion can be implemented by extending the AbstractCriterion class. This class contains a method that verifies the passed in value and provides a default error message that can be displayed to the user if the value does not satisfy the criterion.