mrc logo mrc logo
  • m-Power m-Power
    What is m-Power?
    Overview Demos Build Process Case Studies Specs Pricing Trial
    m-Power Resources
    Overview How-To Videos Webinars & Podcasts White Papers Fact Sheets
  • Solutions Solutions
    What does m-Power build?
    Overview Database Front-Ends Reporting CRM Systems Business Intelligence Dashboards Inventory Management Mobile Apps ERP Enhancements Modernization Spreadsheets to the web MS Access to the web B2B/Web Portals Scheduling Embedded Analytics Web Forms Workflow Data Exploration Budgeting & Forecasting APIs and Web Services Db2 Web Query Alternative
    Solutions by Industry
    Overview Manufacturing Government Foodservice Software Vendors Logistics & Supply Chain Software Consultants Healthcare
  • Services Services
    Development Services Training Mentoring
  • About About
    Overview Partners Press Releases Careers Events Contact Blog
  • Support Support
    Support Home FAQ Documentation Customer Portal Enhancements Updates Roadmap Techblog
Try m-Power

m-Power Manual

Browse:

  • Home
  • Form Validation
  • Validating via a Java External Object
Back to Manual

Validating via a Java External Object

 

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.

Note: 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. The following steps show how you can quickly and easily do this:

  1. Open m-Painter for any existing application, and click "Open File". Check the checkbox for "Show All Files" and then select the Java file for this application. This will open the Java code in m-Painter. Replace the existing code with the Java file referenced earlier in this document.
  2. Press the "Save as" button, be sure to save the file as Validate.java.
  3. Lastly, press the compile icon. This will compile your Java logic into a Class file, which can then be used by m-Power. When successful, you will see a confirmation window to close the window. Congratulations, you have successfully compiled your external object.

Once your object has been built, we need to register it to m-Power before we can use it.

  1. Click "Admin Menu" -> "Custom Code" -> "External Objects" -> "Create New Object"
  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".
  3. Next, click on the "Parameters" icon for the external object you just created. Click "Create Parameter".
  4. 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".
  5. 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.

  6. We have now completed registering the object to m-Power, next we move on to calling the program from our application.
  7. 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.

Created: February 10, 2010 | Modified: June 15, 2015

Search


Browse By Category

Build Process (13)
Starting with m-Power (8)
Retrievals (10)
Reports (15)
Summaries (4)
Maintainers (17)
Graphs (8)
m-Power Data Explorer (4)
General (24)
Calculations (5)
Utilities (9)
m-Power Administration (23)
Security (11)
Freemarker (6)
m-Painter (29)
Form Validation (5)
External Objects & UDFs (12)
Deprecated Documentation (23)
Bootstrap Templates (7)

Popular Tags

Popular Prompt Screens SQL RPG Excel Graph Properties Maintainer Java m-Painter Performance Database Data Dictionary Production Application Properties Graphs Advanced Record Selections Compiling Calculations Dropdowns App Properties Report Form Validation Graphing Parameters Bar Graphs Video Maintainers Reports Tomcat mrc-Productivity Series DB2 Retrievals Administration External Objects Build Process Getting Started Admin Email Dates Bootstrap Templates Summaries Freemarker Retrieval Security

See all tags »

michaels, ross & cole, ltd. (mrc)

Privacy Policy Cookie Policy Cookie Settings Notice at Collection Do Not Sell or Share My Personal Information

mrc (US)

2001 Midwest Road
Suite 310
Oak Brook, IL 60523
630-916-0662

mrc (UK)

Mortlake Business Centre
20 Mortlake High Street
London, SW14 8JN
+44-20-335-59566


© 2024 mrc. All rights reserved.