Custom value editor sample details

You use Decision Center to run this sample.

Running this sample

To open and run this sample:
  1. Log in to the Business console (see Opening Decision Center on the sample server). Use Bea as the username and password.
  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 in the computeOffer package, 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. Click the frequentBuyer decision table in the computeResult package, and then click the Edit button "". You can see your custom value editor by editing a value in the Offer column.
  7. Log out of the Business console.

Rebuilding the sample

To rebuild this sample:
  1. Open the Samples Console (see Running samples from the Samples Console).
  2. In the Samples Commands tab, expand Samples Commands > Decision Center > Custom value editor.
  3. Double-click clean.
  4. Double-click build. Rule Designer builds the custom JAR files.
  5. Double-click repack. Rule Designer repackages the Decision Center application to include the custom JAR files.
  6. 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.

You must declare a mapping between the value editor identifier and the location of the JavaScript editor 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.

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 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.