Error handling in XPages can be done in multiple ways. One part deals with displaying run time errors to users while the other part deals with displaying validation errors.
Displaying runtime errors
By default any error on an XPage is displayed in a very vague manner that is not easily understandable by the developer or the user. Here is an example of how a typical error is displayed for a wrong value in a computed field by default.
Obviously, this does not make any sense to either of the concerned persons. However, in XPages, we have the ability to configure the way the runtime errors are displayed to the users.
In the Domino Designer, open your application navigator and go to the Application properties
of the database you want to configure. Once inside, click the XPages
Under Errors and Timeouts, the field "Error page" is set to "Server Default" and "Display XPage runtime error page" is not checked, as shown in the figure below.
Check Display XPage runtime error page
. Save and close the Application Properties and try to preview the XPages again. The cause of the runtime error is now much easier to understand:
You can also create a custom error XPage with a friendly message shown to the user. The real error can be accessed from a log set up for the purpose. Follow these steps to create a custom error XPage:
- Create a new XPage with your message.
- Click the XPages tab in Application properties.
- Select the XPage from the Error page list in the Errors and Timeouts section.
To add a description of the error you can follow these steps:
- Create a computed field in the custom error XPage.
Here is a sample output:
Validation errors can be displayed in two formats:
- Client-side message: Validation specified as client-side results in the displaying of validation errors within a pop-up dialog box on the page itself. Each error is handled one at a time as the XPage processing stops after the error is displayed.
- Server-side message: By default, validations defined on the Validations tab of the fields are executed client side. They can also be set to execute as server side. When server-side validation is complete, all validation errors are processed and the page is redisplayed to the user for correction.
Which type of validation to use depends on the fact that how much control you want to keep with the server. While the client-side validation is light weight in comparison, the server loose control because of the fact that it happens in the user environment only and no round trip to the server is required. On the other hand, server-side validation needs a round trip to the server for every field and increases load on the server but you can control it better then the client-side validation.
In this section we demonstrate how to make a field required and then display an error message of our choice.
To display a client-side message:
- Go to the Properties view of the selected field and to the Validation tab.
- Mark the field as required and enter a required field message.
- Enter a minimum number of characters and add a validation error message:
Parent topic: 4.0 Coding techniques