Online documentation - Websydian v6.5 |
The ErrorPage function pattern is used to output one or more error messages to the web user.
The ErrorPage function reads and empties the Websydian Message List and writes the error messages to an HTML document. The ErrorPage pattern is a Page Generator function (that inherits from the PageGenerator pattern) with a grid of error message lines added.
The inheritance from the Page Generator function also means that the layout of the error page is guided by the declarations in an HTML Document Template.
In a normal CA Plex client/server application, error messages from validation functions are written to the message log. In a web application, a different approach must be taken because it is impossible for the web application to retrieve messages from the message log.
Instead, a web application must record the errors that occur, and output an error web page informing the user of the problems that occurred during the attempt to service his request. Since more than one error can occur during a single web interaction, Websydian allows the developer to insert error messages into a Message List as they are detected by the application. The ErrorPage pattern retrieves these error messages from the Message List to an error page which is then sent to the user.
The first step is to create an Error Page function by inheriting from the ErrorPage pattern. It is also possible to generate, build and use the ErrorPage function directly as-is from the WSYBASE library but then it will not be possible to do any adjustments to the function.
Usually, only one Error Page function will be defined for an application.
For each type of error that is to be detected, an appropriate error message must be inserted into the Error Message List. A message is added to the Message List by calling the utility meta function InsertErrorMessageInList.
The EventHandlerWithValidation pattern will check for validation functionality defined in the CA Plex model (e.g. validated by triples) and call the InsertErrorMessageInList function for each error found. Note that the EventHandlerWithValidation pattern itself does not call the ErrorPage function to generate the error page.
Once being defined, the Error Page function can be called by other Websydian functions in the model. The Error Page function usually will be called by Event Handler functions, which is where errors are detected.
The Event Handler patterns Insert and Update in the WebEditDialog pattern in the WSYUTIL library contain pre-defined calls to the ErrorPage pattern.
The field Input<ErrorMessage> is defined as input parameter to the ErrorPage function. The value of this parameter field will be shown in the first row of the message grid on the error page and can as such be used as a headline for a number of more specific messages stored in the Websydian Message List, e.g. "Error in update of customer".
If the Message List is empty, the error message in this field will be the only one to appear on the error page. On the other hand, if the Input<ErrorMessage> field is empty, only error messages from the list will be shown in the grid.
In a Websydian application, one Error Page function with its corresponding HTML document template should be developed for each individual message layout that is needed. In most cases, only a single Error Page function is needed to handle all application-generated messages to the user. This single function can be called with different parameters and contents of the Message List.
A very strong part of the CA Plex tool is the ability to define validation functions as separate function objects in the model repository. These validation objects may be declared at different levels (fields, relations, views, and entities) and they are used to store the different business rules of the application.
In this way, the same validation rules will be used in a Windows GUI implementation as in a Websydian implementation. An important point here is that the validation functions should not contain calls to Windows dialog boxes - this will not work when the validation functions are implemented on a web server.
Below are shown the triples to define an Error Page function. No action diagram statements need to be added:
Defining an Error Page function.