Table of Contents |
---|
Introduction
In this tutorial, we'll show you how to make a BeanShell Form Validator. This validator makes sure only values from another table are allowed. Simply put, it acts as a reverse duplicate value checker. We'll have two forms in our example app—one for inputting valid values (Form 1) and another (Form 2) where the validator will be added.
App Structure
Figure 1: Form 1 Fields
Figure 2: Form 1 Details
...
Figure 3: Form 2 Fields
Figure 4: Form 2 Details
Implementation
Now that we have clarified the structure of the sample app, let's start implementing the BeanShell Validator. Here is the code used in the sample app:
...
- Line 18: Change to Field ID you would like to validate
- Line 19: Change the variable of the field element (Optional)
- Line 23: Change the variable of the field value (Optional)
- Line 32: Change the SQL query to match your requirements
Runtime
Figure 5: Form 1 List
...
Figure 6: Invalid Input
Since the value "Test" is not present in the Form 1 List, the validator will flag this submission and reject it.
Figure 6: Invalid Input
Figure 7: Valid Input
Download the Sample App
- APP_KB_beanshellvalidator.jwa
- There is also a second sample app that implements a similar concept to this article but has different requirements. You can download and check out the other sample app here: APP_KB_beanshellValidatorSample.jwa.