This example illustrates several important features of the binding system.

Restrictions

In this example we are specifying a restriction on a property in a type, to restrict the legal values of primaryEmail.

The restriction appears within the email <property> section:

    <j:property name="primaryEmail" type="string">
        <j:restriction>
            <j:maxLength>255</j:maxLength>
            <j:pattern>\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*</j:pattern>  
            <j:validationErrorMessage>Oops!</j:validationErrorMessage> 
        </j:restriction>            
    </j:property>        
    

maxLength indicates how long the string can get.

pattern is a regular expression which indicates legal values (this regular expression is a little too simplistic to handle all email addresses, but it demonstrates the point).

validationErrorMessage is a string to show the user when they enter a value that does not meet the restriction.

When you bind a TextBox to a property with a restriction, text Text Box turns validation on. Every time the user types a character, the system checks the restriction. If the restriction fails, then two properties get set on the text box:

ID_isInvalid - becomes true if the text fails to validate.

ID_validationErrorMessage - set to an error message from the validation system if the text fails to validate - in this case it uses the message defined by the restriction: "Oops!".

To display the error message to the user, we've created a red label whose visible property is tied to the invalid property, and whose text is set to the invalidMessage:

    
     <j:Label style="color:red" 
              visible="#bind(controls.emailEditor.isInvalid)"
              text="#bind(controls.emailEditor.validationErrorMessage)"/>
    

When the user types an invalid email, the little label turns on and shows the user a message.

Properties and Display Names

Display Names

The primaryEmail property in the example above also defines a displayName:

    <j:property name="primaryEmail" type="Email">
        <j:displayName>Email</j:displayName>
    </j:property>
    

DataObjects in the Jitsu runtime have an associated "reflection" table, which contains meta information about the property used by the runtime. Both Restrictions and display names are stored in the reflection table.

You can access reflection information through data binding. Writing:

    <j:Label text="#bind(person.reflection.firstName.displayName)"/>
     

tells the binding engine to obtain the "reflection" object for the person, and then drill into that for reflection information on the property called firstName, retrieving that property's displayName. This is useful in a "property grid" control, where you are binding to properties of an object but you don't know their names beforehand.