![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Rules Guide
CHAPTER 4
This chapter describes how to create and edit rules in exteNd Director. It has the following sections:
For background information about using rules in exteNd Director applications, see How You Use Rules.
The Rule Editor is where you create rules to use in a portlet or JSP page in your application. You build a rule by selecting from predefined conditions and actions. Each rule definition is saved as an XML file in a specified directory in your exteNd Director project.
Graphically, a rule is a combination of one or more conditions (When) and one or more actions (Do) that produces some result. It has the form:
When the combination of some conditions is true, Do some actions; Otherwise Do some other actions.
Each When-Do statement is called a node and maps to a decision node in XML. You can also embed case statements within a parent node, as described in Using cases.
The Otherwise Do section is executed only when all nodes in the rule evaluate to false.
You invoke the rule name when firing a rule.
You can specify a rule owner as part of the identifier; doing so allows you to organize your rules by application and avoids possible naming conflicts with other applications. You can use the Rule API to access rules associated with an owner.
(Optional) To specify the owner, use the format ownername.rulename. For example:
A condition is a Java class containing logic that returns true or false. The installed conditions are implemented as JavaBeans that in many cases allow you to set relevant properties. You can add multiple conditions for a rule and manipulate those conditions in various ways.
Default condition The default value for a condition is When:On. In cases where you always want the associated actions to execute (for certain types of pipelines, for example), you can leave the default and just select actions for the Do section.
Reusing a series of conditions If you have a series of conditions that you might want to reuse in another rule, you can create a macro for it. For more information, see Working with condition and action macros.
In the Rule Editor, select the When section where you want to enter the condition and right-click to display the condition popup menu:
The condition property panel displays. The dropdown lists all installed conditions plus any custom conditions you have written and deployed.
Select the condition you want.
The settable properties for the condition display on the panel.
For information about using the installed conditions, see Installed Conditions.
Set the properties as required and exit the panel.
The condition description appears in the Rule Editor. For example, choosing the Check Month condition displays a result like this:
In the Rule Editor, select the description of the condition below which you want to add a condition. To add the condition at the top, select the appropriate When element.
Add the condition as described in To add a condition:.
By default, the condition is added with the AND operator, meaning that this condition and the previous condition must be true for the Do section to execute.
Selecting a logical operator for processing When you have two or more conditions in a series, you can specify the OR operator if you want either condition to be true and specify the NOT operator if you want a condition to be false.
To toggle the operator between AND and OR:
To toggle the NOT operator to and from NOT:
This table lists other ways to edit conditions in the Rule Editor:
To |
Do this |
---|---|
Move a condition up or down |
|
Edit condition properties |
|
Delete a condition |
If you want a condition not to be evaluated but do not want to delete it from the rule, you can deactivate it.
To toggle a condition between activate and deactivate:
An action is a Java class that does something based on the condition it is associated with in a rule. Actions are added to the Do and Otherwise Do sections of a decision node. The Do section is activated if the When section of the node evaluates to true. The Otherwise Do section is executed when the When section is false.
For many of the installed actions, you can set relevant properties in the Rule Editor. You can also embed cases in an action and control the processing between decision nodes.
Default action The default value for an action is return true.
To specify any other action (including return false), you need to add an action.
With the Rule Editor open, select the Do or Otherwise Do section where you want to enter the action, and right-click to display the conditions.
The action property panel displays. The dropdown lists all the installed actions plus any custom actions you have written and deployed.
The settable properties for the condition display on the panel.
For information about properties, see Installed Actions.
Set the properties as required and exit the panel.
The action description appears in the Rule Editor. For example, choosing the DenyAccess action displays a result like this:
To add additional actions for this node, repeat this procedure.
This section describes other ways to edit actions in the Rule Editor:
To |
Do this |
---|---|
Move an action up or down |
|
Edit action properties |
|
Delete an action |
If you want a condition not to be evaluated but do not want to delete it from the rule, you can deactivate it.
To toggle an action between activate and deactivate:
You can add When-Do statements to a parent node to make case statements (or child nodes) in a rule. Adding cases expands the tree control for the rule. You can add a case at the top (When) or in an embedded (Do) level of your logic:
You can handle the flow of processing for cases in two ways:
Break specifies that if the When section is true, the rule ends with that case.
Continue specifies that after the rule does the actions for the case, it goes on to evaluate the next node.
Select the When, Do, or Otherwise Do section where you want to add a case.
Repeat Step 2 for each additional case.
Use the Rule Editor to add conditions and actions for each node.
To toggle the case processing value:
If you have a complex rule with many cases, you can add a description for each to make them easier to identify. The description appears next to the When section that begins the case.
Select the When section for the case you want to add the description to.
Right-click and choose Edit Description from the popup menu.
The Rule Editor provides various other ways to manipulate cases.
Right-click and select the appropriate command from the popup menu:
There are a couple of ways you can test rules before deploying them:
The Run Rule command displays rule return values in the development environment Output Pane. Use this command to verify that the rule is returning the correct values at each logic point. The Run Rule command does not display actual return values, like HTML data.
With the Rule Editor open, select the Run Rule icon from the exteNd Director menu:
Output for return values displays on the development environment Output Pane.
TIP: You can use the RuleWrapper portlet in the installed MyPortal application to display the result of any rule that returns HTML.
With the rule open in the Rule Editor, select File>Save from the exteNd Director menu or press Ctrl-S.
The contents of the rule definitions folder display in your project resource set.
Navigate to the location of the rule XML descriptor in your project.
Macros allow you to save conditions and actions in reusable groups. For example, you might have standard logic that uses multiple conditions. Similarly, you might have a group of discrete actions that you want to fire under different conditions. Macros provide a higher level of organization while preserving the flexibility of using single conditions and actions.
Each macro is saved as an XML file. After you create a macro, you can add it to a condition and action in the Rule Editor.
This section describes how to create a condition macro and use it in a rule.
Select the Condition Macro icon:
Specify a name and description at the top of the Macro Editor.
The name you specify is the default file name for the macro XML file.
Select a condition from the dropdown, as described in To add a condition:.
To add another condition, select the existing condition and right-click.
Add more conditions, as described in To add more conditions:.
Select an operator, as described in Selecting a logical operator for processing.
Edit, move, or delete conditions, as described in Editing and deleting conditions.
When you save a condition macro, exteNd Director opens the appropriate subdirectory of your project's resource set.
With your macro open in the Condition Macro Editor, select File>Save from the exteNd Director menu or press Ctrl-S.
The contents of the rule-conditions-macro folder display in your project resource set.
Navigate to the location of the condition macro descriptor.
After you save the macro in an appropriate directory, you can use it in a rule.
To use a condition macro in a rule:
Select the point in the When section where you want to add the macro.
Right-click and choose Insert Macro or Add Macro.
To delete, inactivate, or move a macro within the rule:
This section describes how to create an action macro and use it in the Rule Editor.
Specify a name and description at the top of the Action Macro Editor.
The name you specify is the default file name for the macro XML file.
Select an action from the dropdown menu, as described in To add actions:.
To add another action, select the existing action and right-click.
Add more actions, as described in To add a case for an action:.
Edit, move, or delete actions, as described in Editing and deleting actions.
When you save an action macro, exteNd Director opens the appropriate subdirectory of your project's resource set.
With your macro open in the Action Macro Editor, select File>Save from the exteNd Director menu or press Ctrl-S.
The contents of the rule-action-macro folder display in your project resource set.
Navigate to the location of the action macro descriptor.
After you save the action macro in an appropriate directory, you can use it in a rule.
To use an action macro in a rule:
Select the point in the Do section where you want to add the macro.
Right-click and choose Insert Macro or Add Macro.
To delete, inactivate, or move a macro within a rule:
Copyright © 2003 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved. more ...