1. Home
  2. Knowledge Base
  3. Deprecated Documentation
  4. Validating via a Java External Object

Validating via a Java External Object

mrc recommends using the Workflow Designer to validate user input going forward.

Overview

This document will explain how to call an external object Java program for validity checking. For basic information regarding validity checking please see this document.

The source code for the Java used in this example can be found here. The purpose of this object is to check to see if the start date is less than the end date.

This is a very simple example that is meant to demonstrate how to create and setup a Java validity checking external object. Your Java program could be designed to check anything!

In the included example, we are creating a Java program called Validate within the MRCWORKLIB data dictionary. Within this program are three parameters:

  • ERROR — 99 length, used for setting the error message.
  • strdatex — 8,0 length, used for accepting the start date, passed from the servlet.
  • enddatex — 8,0 length, used for accepting the end date, passed from the servlet.

In the example, we setup a simple If/Else If statement that checks to see if the start date is greater than the end date. If it is, the Java program will return the error message, which has been set to read: “Starting Date is greater than End Date”. However, if the start date is smaller or equal to the end date, the Java Program will return the error message, which will be set to blank. This example also has three other cases it tests for:

  1. If both date fields are blank, the error “You have not entered any dates” will be displayed.
  2. If the start date has been omitted, the error “You must enter a starting date” will be displayed.
  3. If the end date has been omitted, the error “You must enter an end date” will be displayed.

The code provided still needs to be compiled. If you do not have easy access to a Java compiling tool, you can use m-Painter.
Once your object has been built, we need to register it to m-Power before we can use it.

  1. Click “Admin” -> “External Objects” -> “Create New”
  2. Specify Validate for your Object Name. Specify a meaningful object description. Select the “Java Method” radio button for Object Type. Specify MRCWORKLIB.Validate for the Class name, and valid_fields for the Method name. Click “Accept”.
  1. Next, click on the “View Parms” button for the external object you just created. Click “Create New Parameter”.
  2. Validity external objects require that the error message field is the first parameter used. It also requires that the description contains the text *VALID, the error message to be 99 alpha, and that the field is not required. By making this field non-required, we are allowing m-Power to pass this field a blank entry, and allowing it to receive the appropriate text from the Java program. Once this has been completed, press “Accept”.
  1. Next, we should create two more parameters (for the start and end date). They need to be created in the same order they were listed in the Java program. So we will create Start Date first, then End date. Both fields should be 8,0 and be set to be Required Fields. They are required because they are both necessary for the external object to function correctly.
  1. We have now completed registering the object to m-Power, next we move on to calling the program from our application.
  2. Open your Maintenance or Report application, and navigate to the External Objects screen. Add your new external object to your application, using the *FLDVALID location (report users will use the *RUNVALID location), and mapping the 2nd and 3rd parameter. The *FLDVALID location will call your external object after your user submits the form, but before the data is written to the database.

After compiling and running my application, here is my result. As you can see below, I have entered a start date that has occurred after my end date. As a result, this error is returned to me and the data is not written to the table. In the second example, you can see that my application has correctly informed me that I need to specify an end date.

However, after correcting my date, you can see that no error message is returned and the data writes to the table successfully!

Notes

  • The name of your .java file must match the class and file name. Notice in our example, we always used “Validate”.
  • In Java, case matters: Validate is different than validate.
  • If you decided to build your java program through m-Painter, both the .java and .class files can be found in: \m-power\mrcjava\WEB-INF\classes\MRCWORKLIB
  • Feel free to save this java object in any data dictionary, however you will need to change line 1 of your Java code to point to the correct data dictionary. Also, you will need to reference the correct data dictionary when registering your object’s class path.
  • If you would like to deploy your java external object programs via a jar file and using your own qualified package names, you can do so by placing the jar file in the mrcjava\WEB-INF\lib folder. Be sure to register each external object using the fully qualified class name (for example com.mrc.externalobjects.MyClass) in the “Class name” field.
Updated on June 20, 2023

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support