Learning XPages Part 34 : Server Side Validation

In the last part we created some very simple
client side validation of the data for the Job Title field, In this part
I’ll switch it over to a server based validation to show you the difference
between the two.

When you first install your Domino 8.5
server, client side validation is set as the server wide default validation
method. You can if you want setup the server so the server default for
validation is server side by editing a file on the notesdirxspnfs folder
called xsp.properties and changing the xsp.client.validation line to false
but this will effect ALL Xpages applications on the server and if the application
has not been written with this in mind you may run into some issues so
my personal recommendation is to leave this at the default and enable server
side validation either at the application level or even at the XPage control

To set up server side validation at
the application level you will need to open the ‘Application Properties’
in the main domino designer outline for your application and then switch
to the XPages tab and turn off the client side validation option :

A picture named M2

The last level at which you can turn
off the client side validation is at the edit controls level. Select the
JobTitle editbox we were working with in the last part and goto the ‘All
Properties’ section. Under ‘Data’ you’ll see the disableClientSideValidation
option that can be set to true or false ( or even computed ).

A picture named M3

When we had client side validation enabled
the error message was presented to us in a standard web browser dialog
box. With server side validation we need to create a place on the XPage
where the error will be displayed. if you look at the controls section
in the domino designer you’ll see two controls at the end of the ‘core
controls’ section for error display.

A picture named M4

‘Display Error’ will display a single
error message and is linked to a single editable control on your XPage
and ‘Display Errors’ will display all the errors on the XPage. To demonstrate
both types I have added a ‘Display Errors’ section above my tabbed panel
and a ‘Display Error’ control beside the JobTitle editbox.

A picture named M5

The properties for both controls are
very similar with the main difference being that the ‘Display Error’ control
must be associated with an edit control

A picture named M6

Now if we save and preview our XPage
the error messages that we created in the last section will appear where
and the document won’t be saved.

A picture named M7

A picture named M8

They look pretty plain right now. So
why not add a styleClass of ‘lotusMessage’. I’m going to add the single
‘Display Error’ to each of the fields that I want to validate and remove
the ‘Display Errors’ control from my final version of the application.

In the next part I’ll add some advanced
validation to show you how to use RegEx to make sure the phone number does
not contain invalid characters.

Tagged with: , , ,
Posted in None
%d bloggers like this: