Business console custom value editor sample details

You use Decision Center to run this sample.

Running this sample

To open and run this sample:
  1. In your web browser, log in to the Business console at http://localhost:<PORT>/decisioncenter. Use the following credentials:
    • User name: Bea
    • Password: Bea
  2. Click Library to open the tab. Click the Value Editor Service box anywhere but the name, and then click the main branch.
  3. To see the new value editor, compose a new rule:
    1. Click Value Editor Service in Decision Artifacts. The content view displays the rules in the decision service.
    2. Click the Create button "", and click New Rule.
    3. Type Test as the name of the rule, and then click Create.
    4. In the rule editor, click <action>, then select set the message of <a promotional offer> to <a string>, and a promotional offer. The custom editor opens.
    5. Click the arrow to see the possible offers.
    6. Select one and click OK.
      Note: If your browser has a spellchecker, it might underline the text in red.
    7. Click Cancel. You do not have to save the rule.
  4. Click the offer rule, and then click the Edit button "".
  5. Double-click #BFGHFDF in the condition part of the rule. You can see that your custom value editor is working correctly because the display changes for each entry that you select.
  6. Log out of the Business console.

You can also run this sample in the Enterprise console:

  1. Sign in to the console at http://localhost:<PORT>/teamserver. Use the following credentials:
    • User name: Bea
    • Password: Bea
  2. Click Options. Select Intellirule editor as the rule editor in the user options, and click OK.
  3. On the Home page, select Work on a decision service, and then Value Editor Service.
  4. Click the Explore tab.
  5. Click the Quick Edit icon next to the Offer rule.
  6. Double-click #BFGHFDF in the condition part of the rule. You can see the same custom value editor that is in the Business console.

Rebuilding the sample

To rebuild this sample:
  1. In the Samples Commands view, navigate to Samples Commands > Decision Center > Business Console custom value editor.
  2. Double-click clean.
  3. Double-click build. Rule Designer builds the custom JAR files.
  4. Double-click repack. Rule Designer repackages the Decision Center application to include the custom JAR files.
  5. Double-click run. Rule Designer deploys the repackaged application.

How this sample works

The project Value Editor Service has a BOM that contains the class PromotionalOffer, which has defined custom properties.

You use the properties as follows:
  • Associate the custom value editor graphical component with the BOM class valueditor. In this sample, the identifier is sample.myeditor.editor.

  • Define the processing, persistence, and representation of data values that are managed by the custom value editor in the rule editors, and how the value editor integrates with the rule editors valueDescriptor and DecoratedValueDescriptor.prefix.

  • Define how the textual representation of its data values is converted in the rules through valueTranslator. In this sample, the identifier is servervalueeditor.FilterValueTranslator.

For more information, see Sample: Custom value editor.

You must declare a mapping between the value editor identifier and the value editor class in Decision Center. For the Enterprise console, register the teamserver.web.intelliruleEditor.sample.myeditor.editor key to the provider class. To do so, use the set-config-param target, which registers the decisioncenter.web.core.intelliruleEditor.sample.myeditor.editor key to the fully qualified name of the value editor class businessvalueeditor.OfferValueEditorProvider. This provider defines the location of the JavaScript file.

In this sample, the run target does this operation.

After you write your rule, you must associate a value translator to your data type (BOM class) to help Decision Center convert your rule into its IRL representation. Decision Center converts the promotional offer code into IRL by instantiating the PromotionalOffer class. You can examine the FilterValueTranslator.translateValue method.

In this sample, the conversion is done with FilterValueTranslator. The mapping between the BOM member and the FilterValueTranslator class is done by BOM custom properties, so you must provide only the class in your custom JAR file.

The repack Ant target in the build.xml file uses the repackage-ear Decision Center Ant task to rebuild the Decision Center application to include the JavaScript file that defines the custom value editor and the custom JAR files that contain the value editor and the value converter.

Source files

This sample is located in <InstallDir>/teamserver/samples/businessvalueeditor.

The src/businessvalueeditor folder contains the following files:
  • OfferValueEditorProvider.java: The value editor class that implements IlrClientScriptFileValueEditorProvider. It points to the JavaScript file that defines the editor.

  • SampleDataProvider.java: The data provider class for this sample. It is used on the server side to build the data that is shown on the client side.

  • SampleValueEditorServlet.java: The servlet class that builds the data to be shown in the client that uses JSON classes.

The src/servervalueeditor folder contains the following API:
  • FilterValueTranslator.java: A class to define textual representation conversion into rules.

The JavaScript that defines the editor is located in js/OfferValueEditor.js:
  • It calls a servlet to get the data to be shown from the server.
  • It builds the HTML editor that uses the data that is obtained from the server.
  • It returns the selected data to the server.

You can also view and modify the sample source files in Rule Designer. To import the sample into your workspace, click the Import projects link in the Samples and Tutorials view, and switch to the Java™ perspective.