Learning XPages Part 33⅓ : Simple Data Validation.
Tags : Lotus Domino XPages Validation
Bookmark :
Now that we have given the ability for the end user to edit a document in their web browser we need to make sure that what they enter does not contain any invalid characters. An example of this might be the person's job title could be restricted to 50 characters, or phone numbers can only contain the +, - and numerics. There are two distinct ways to do data validation in XPages, one is client side and the other is server side. My preference is for client side validation as it does not involve the user having to send data to the server and then wait for it to come back but I will show you both methods so you can decided which option is right for you.
lets start by looking at the simple data validation options available in XPages. Start by opening our content_Person custom control again we will add a very simple validation to the Job Title field to make sure that it is filled in and that it is not more then 50 characters in length and not less then 10 characters.
Select the JobTitle field in the custom control and look down to the properties box below. Select the 'Validation' tab and then you can tick the 'required' box and fill in an error message to be displayed when the user doesn't fill in any entry for the field.
To the right of this section you can see the string length validation properties :
You may notice that these validation options all have the little diamond beside them. This means you can write JavaScript to compute the values for the fields if your application requires it. A good example is maybe you would want to turn off the 'required' part of a field for somebody with a 'DataManager' role in the ACL so that they can go in and quickly edit a document without having to make sure all the required fields have data in them.
So how does the XPage know that this is a string? Well if you look back on the 'Data' tab of the properties to the right there is a dropdown field to specify the type.
Changing the type of the data field will show different options on the validation tab, for example if the field is a number then you can specify the range the numbers must be within, if the field is a date you can specify the date range the value must be within.
There are also a couple of hidden validation options that can be access through the 'All properties' tab under 'validators'. Here is what our current validation options entered about look like in here :
If we save and refresh our XPage now and then go into edit mode and empty out the Job Title field and save the document you will see the web browser pop up with the error message we specified.
This is an example of client side validation. In the next part I'll show you how to convert this to a server side validation so that you can see the difference.
NOTE : I have not covered creating the 'Save' action yet but it is as easy as duplicating the 'edit document' button and changing the simple action to save document, I will cover this button in a later part.
Bookmark :
Now that we have given the ability for the end user to edit a document in their web browser we need to make sure that what they enter does not contain any invalid characters. An example of this might be the person's job title could be restricted to 50 characters, or phone numbers can only contain the +, - and numerics. There are two distinct ways to do data validation in XPages, one is client side and the other is server side. My preference is for client side validation as it does not involve the user having to send data to the server and then wait for it to come back but I will show you both methods so you can decided which option is right for you.
lets start by looking at the simple data validation options available in XPages. Start by opening our content_Person custom control again we will add a very simple validation to the Job Title field to make sure that it is filled in and that it is not more then 50 characters in length and not less then 10 characters.
Select the JobTitle field in the custom control and look down to the properties box below. Select the 'Validation' tab and then you can tick the 'required' box and fill in an error message to be displayed when the user doesn't fill in any entry for the field.
To the right of this section you can see the string length validation properties :
You may notice that these validation options all have the little diamond beside them. This means you can write JavaScript to compute the values for the fields if your application requires it. A good example is maybe you would want to turn off the 'required' part of a field for somebody with a 'DataManager' role in the ACL so that they can go in and quickly edit a document without having to make sure all the required fields have data in them.
So how does the XPage know that this is a string? Well if you look back on the 'Data' tab of the properties to the right there is a dropdown field to specify the type.
Changing the type of the data field will show different options on the validation tab, for example if the field is a number then you can specify the range the numbers must be within, if the field is a date you can specify the date range the value must be within.
There are also a couple of hidden validation options that can be access through the 'All properties' tab under 'validators'. Here is what our current validation options entered about look like in here :
If we save and refresh our XPage now and then go into edit mode and empty out the Job Title field and save the document you will see the web browser pop up with the error message we specified.
This is an example of client side validation. In the next part I'll show you how to convert this to a server side validation so that you can see the difference.
NOTE : I have not covered creating the 'Save' action yet but it is as easy as duplicating the 'edit document' button and changing the simple action to save document, I will cover this button in a later part.
Download File xPhoneP33.zip
Comments
Posted by Bruce Elgort At 10:36:41 AM On 03/05/2009 | - Website - |
You Rock Dec!
Posted by Phil Randolph At 12:08:59 PM On 03/05/2009 | - Website - |
NOTE: This is an EXCELLENT tutorial, keep it up.
Posted by Larry At 12:07:45 PM On 03/06/2009 | - Website - |
i have been trying some validation, but I am doing a @DBlookup to get some values for other fields based on a name field. the problem I am having, is that the validation is kicking in BEFORE the @DbLookup is getting the chance to fill in the values.
Anyone know a way around this?
Thanks
Posted by Jamie Grant At 08:51:14 AM On 03/25/2009 | - Website - |