| |
How to Validate Against a File or Routine, and Return an Error Message to a Java servlet Maintenance Application |
| by Margaret Jeronim |
|
Last month, we covered the ins and outs of creating an error message using validation techniques in your CGI applications. And, after many concerned phone calls, we felt it would be wise to extend the series, and cover the method for adding an error message to Java servlet applications as well.
So, how can you display a custom error message when a user enters an incorrect value in a Java servlet maintenance application ?
To begin, download this external object example:OVLDSRVEXP (dated 9/22/03).
This can be used as a guideline to validate a value entered in a field and display custom error messages if that value is incorrect.
In the following example, the source of the external object was modified (after the download) to validate a salesman number and display the error message: 'Wrong salesman number entered' when the validation fails.
This external object is using two parameters. The first parameter is the error message defined as 99 alpha field. If this parameter is returned as a blank to the calling servlet, then the validation has passed successfully. If not, then the error message is displayed.
The second parameter is the field that you want to validate. In this example it is the salesman number, and it is defined as a numeric 3.0. (see the example below).
****************S o u r c e L i s t i n g ***********************************
| 0001.00 * | | | | | 0002.00 C | | | | |
0003.00 C | *entry | plist | | |
0004.00 C | | parm | @error | 99 |
0005.00 C | | parm | @sals | 3 0 |
0006.00 C | | | | |
0007.00 C | eval; | @error | = *blanks | |
0008.00 C | if | @sals | = 0 | |
0009.00 C | eval | @error; | = 'Wrong salesman number entered.' | |
0010.00 C | endif | | | |
0011.00 C | | | | |
0012.00 C | eval | *inlr | =*on | |
| |
****************** End of data ***************************************** |
After the modification, the source is compiled into an object by choosing option 14 - Compile next to the objects name. In the next step, the object is defined in option 44 of mrc by pressing F6 to 'Create'. The object must be defined as 'Object type' R. (see figures 1 amd 1a)

Figure 1
Figure 1a
Since the external object requires two parameters, these also need to be declared.
The first parameter must contain the text *VALID in the parameter description (see figures 2 and 2a).

Figure 2
Figure 2a
Those parameters are defined as 'Selected field required ' N .
After the declaration the external object is called into the servlet maintenance application by choosing option 8.
The error message parameter should not be mapped to any field in the application.
The salesman number parameter needs to be mapped to the salesman number field in your application. Select FIELD SCREEN VALIDITY CHECKING AND ERROR HANDLING *FLDVALID template location for calling this external object .
Please see figure 3 and 3a for B&G screen call to this object
and figure 3b for BED version of the external object call.

Figure 3

Figure 3a

Figure 3b
Now, just compile your application. See figure 4 below.

Figure 4
You can modify the sample source by including multiple error messages with multiple field validation. Defining each error message and field validation as a separate external object will allow you to reuse external objects in multiple applications.
|
|
 |
mrc publishes this newsletter on a monthly basis. Subscription is free of charge. Please send any questions or comments about this newsletter to news@mrc-productivity.com. This newsletter is edited by Heather Gately.
To unsubscribe, please just reply to this e-mail with Unsubscribe in the subject line.
View our privacy promise.
|
 |
|