Skip to main content

SimpleValueTypes

A SimpleValueType is a ValueType that can be directly mapped to types in the code.

Common SimpleValueTypes include String, BigString, Integer, Double, Boolean, Timestamp and Date.

It is possible to create new SimpleValueTypes by adding them to a Component. Each SimpleValueType can have a protoType, which is another SimpleValueType. A SimpleValueType inherits the behaviour of its prototype, except for the behaviour that is defined by the Type itself.

<valueType name="DocumentName" type="elements::SimpleValueType">
<prototype name="String"/>
</valueType>

Provided types

Types provided by prime-core

TypeDescription
StringA string value up to 255 characters.
BigStringA string value up to 16384 characters.
BooleanA boolean (true/false) value.
IntegerA 32-bit signed integer value.
LongA 64-bit signed integer value.
DoubleA double-precision floating-point value.
DateDate values without time.
TimestampDate values with time.
ByteArrayAn array of byte values. Often used to represent binary data.
Text valuetype

In addition to the types above, prime-core also provides the ValueType Text. This type is the base type for all types that represent a string value, but it does not provide any information or constraints in the model (such as maximum length) and should therefor not be used as a type for any field. This means that there's no way to ensure consistent use across different implementations.

When used in a JEE application, Text fields will only be constrained by whatever the persistence provider decides is the default translation for any given type of database. Any error that might occur due to (for example) size limits, will only occur at the last step of handling the data, when it has already reached the database.

Types provided by Expanders

TypeDescription
ShortA 16-bit signed integer value.
MarkupStringThis types extends BigString, but also adds a rich-text editor in the Knockout UI.

Additional types

In addition to the types that are provided by prime-core and Expanders, the standard-types expansion resource also provides some additional types for more specific use-cases such as variable length strings, email addresses and more.

Restrictions

After defining a new SimpleValueType, you can add restrictions on what values are valid for this specific type.

There are several restrictions that can be added to the model:

NotNull

Add a NotNull restriction to a SimpleValueType to prevent the values from being undefined.

<valueType name="StrictBoolean" type="elements::SimpleValueType">
<prototype name="Boolean"/>
<restrictions>
<restriction type="elements::NotNull"/>
</restrictions>
</valueType>
tip

For Strings, this restriction also rejects empty Strings. If necessary, you can provide a custom undefined check for your own types:

Customizing Undefined Checks

StringLength

You can limit the length of a String to a maximum length with the StringLength restriction. For standard Strings, this limit is set to 255 characters. By adding restriction to your own SimpleValueType extending String, you can redefine this limit to be either smaller or larger than this limit.

It is also possible to define a minimum length if applicable. Combine this with the NotNull restriction to also prevent null values.

<valueType name="SmallString" type="elements::SimpleValueType">
<prototype name="String"/>
<restrictions>
<restriction type="elements::StringLength">
<minimum>2</minimum>
<maximum>16</maximum>
</restriction>
</restrictions>
</valueType>

StringPattern

A StringPattern restriction provides a regex to check values against.

<valueType name="Email" type="elements::SimpleValueType">
<prototype name="String"/>
<restrictions>
<restriction type="elements::StringPattern">
<regex>[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+</regex>
</restriction>
</restrictions>
</valueType>

NumberBounds

A NumberBounds restriction can be added to an Integer or Double to set a minimum and/or maximum value for a number.

<valueType name="Rating" type="elements::SimpleValueType">
<prototype name="Integer"/>
<restrictions>
<restriction type="elements::NumberBounds">
<minimum>1.0</minimum>
<maximum>10.0</maximum>
<includeMinimum>true</includeMinimum>
<includeMaximum>true</includeMaximum>
</restriction>
</restrictions>
</valueType>

Digits

A Digits restriction limits the number of digits in the integer part and/or the fraction part of a number.

<valueType name="Price" type="elements::SimpleValueType">
<prototype name="Double"/>
<restrictions>
<restriction type="elements::Digits">
<fraction>2</fraction>
</restriction>
</restrictions>
</valueType>

Past/Future

Dates can be limited with the Past or Future restriction. Which force a value to be in the past or the future.

<valueType name="BirthDay" type="elements::SimpleValueType">
<prototype name="Date"/>
<restrictions>
<restriction type="elements::Past"/>
</restrictions>
</valueType>