Commentary - Sample Code (RedirectCommentary)

The Commentary plugin in this example does the following:

 

The sample code will cover the following:

Setup

This sample code needs the following to run:

About the RedirectCommentary plugin

To setup this scenario:

  1. Create the Rulebase in Oracle Policy Modeling, and run Build
  2. Copy the rulebase .zip file from the project output directory (for example, C:\projects\Parents and Children\Development\output) to the rulebase folder in the Web Determinations (for example, <webroot>\WEB-INF\classes\rulebase)
  3. Copy the code for the RedirectCommentary plugin
  4. Modify the static map (variable redirectMap) used for the targets and URL mappings in the code if necessary
  5. Modify the getInstance(arguments) method for registration of the plugin with the rulebase if necessary
  6. Compile and JAR the RedirectCommentary
  7. Install the JAR file on the Web Determinations. More info in article: Create a Plugin
  8. Run a Web Determinations Interview

How the RedirectCommentary plugin works

Once registered, Web Determinations will call the RedirectCommentary.isCommentaryEnabled() when a screen is to be displayed. RedirectCommentary always returns true.

When a screen is to be displayed, Web Determinations calls RedirectCommentary.hasCommentary() method for the screen itself, to check if commentary information exists for the screen. The same method is also called for each attribute control to be displayed in the screen. RedirectCommentary.hasCommentary() uses the target information and the locale information from InterviewSession to verify if a URL exists for the target in the mapping object

If RedirectCommentary.hasCommentary() returns true for a target, its label is rendered as a link.

When the user clicks on the label link, Web Determinations calls RedirectCommentary.isCommentaryRedirect() to check if the commentary for the target (the clicked label link) returns URL or HTML content. RedirectCommentary plugin always returns true.

Web Determinations then calls RedirectCommentary.getCommentaryContent() to get the URL for the target. RedirectCommentary simply retrieves the value from the mapping object using the target String and the locale from the InterviewSession as the key. RedirectCommentary returns the URL value as is, and Web Determinations displays the webpage of the URL as commentary.

A similar sequence of the above can be seen in Commentary Plugin

Source Code

Note the inline comments

 

RedirectCommentary.java