Adding business logic

Business logic is any Java code that is invoked as an action when an event occurs, such as a host screen being recognized or your HATS application being started. Business logic is specific to the application and is not provided as part of HATS. You can use business logic to extend your HATS application to integrate with other data sources, such as a database or an Integration Object. For example, you can read the contents of a file or a database into HATS global variables and use the global variables to fill in a drop-down list or pop-up to be used in the application's GUI pages.

HATS automatically updates your class loader policy when you include HATS business logic in your HATS Web project. This updates the default WAR class loader policy of your HATS application to Single class loader for application.

You can create business logic and add it to your project using the Create Business Logic wizard. To invoke this wizard, right-click in the HATS Projects tab of the HATS Toolkit, and click New HATS > Business Logic.

In the Create Business Logic wizard, specify the project you want to add the business logic to and supply the Java class name. The default package name is projectName.businessLogic, but you can change this in Studio Preferences. Optionally, you can supply a package name or click Browse to select an existing Java package. If you want your business logic to include methods for easy access to the project global variables, or to remove project global variables, select the Create global variable helper methods check box. Click Finish when you have provided the required information.

After you create your business logic class, you will want to link it to one or more screen or application events so it is executed when that event occurs. Edit each event (application event or screen customization) to which you want to add the link. On the Actions tab, click Add, select Execute business logic, then fill in the details for your business logic class. Refer to Working with screen events for information about editing both screen customization and events.

You can see the business logic files in the project by expanding the Source folder on the HATS Project View tab of the HATS Toolkit. Each package name or class name appears in the Source folder. Expand the package name folder to see the Java class name. Click the class name to edit the class. The Source folder can also include other Java files that have been imported into your HATS project.

If you use the Create Business Logic wizard to create business logic, the method that is invoked by the execute action is named execute by default. If you write your own class, the method must have the following attributes:
  • Be marked public and static
  • Have a return type of void
  • Accept a com.ibm.hats.common.IBusinessLogicInformation object as the only parameter
The method must use this form, followed by your own business logic code:
public static void myMethod (IBusinessLogicInformation businesslogic)
The IBusinessLogicInformation object that is passed to your custom Java code enables you to access and use or modify various objects and settings of your HATS project. These include:
  • The com.ibm.hats.runtime.IRequest class, which returns an object representing the request made to the HATS runtime and provides access to request parameters.
  • The com.ibm.hats.runtime.IResponse class, which returns an object representing the response from the HATS runtime.
  • The getConnectionMap() method, which returns a java.util.Map that contains the settings for the connection information that you provided for the application.
  • The getGlobalVariables() method, which returns a java.util.Hashtable of global variables for this application instance. This table does not include shared global variables.
  • The getSharedGlobalVariables() method, which returns a java.util.Hashtable of shared global variables for this application instance.
  • Class properties, which provide default settings for objects such as components and widgets
  • The com.ibm.hats.common.HostScreen object, which contains host screen information
  • The java.util.Locale class of the client
  • The com.ibm.hats.common.TextReplacementList values and settings
  • The client session identifier string (returned by getter methods in the business logic template that the Create Business Logic wizard provides)
  • The current screen orientation of bidirectional sessions
  • The existence of the Screen Reverse button in the browser for bidirectional sessions

For more information about the classes made available to you, see the HATS API documentation in the HATS Knowledge Center at https://www.ibm.com/docs/en/hats/10.0.0?topic=hats-api-references-javadoc for the IBusinessLogicInformation class. Since IBusinessLogicInformation extends the IBaseInfo class, several of these APIs are defined in the IBaseInfo class.