Try OpenEdge Now
skip to main content
Application Developer's Guide
Using the Rule Wizard framework : Specifying alternatives
 

Specifying alternatives

A frequently occurring situation is when two macros exist but only one macro may contain valid values at a time. The user must decide which macro contains the valid values. The macro of type composite provide the groupComponents and selectedMacro properties. The first property contains the names of the component macros which belong to this group (this means only one contains valid values) and the latter (selectedMacro) contains the default value (which component is valid when the components first display). Besides components belonging to a group, a composite macro may contain components that are valid at all times. Slightly modifying the third example shows the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE template SYSTEM "resources/ruleTemplate.dtd" >
<template name="ex4">
<screen number="10">
    <editor macro="aggregate">
        <editor macro="text" label="Text">
            <parameter name="columns" value="30"/>
            <label-constraints fill="HORIZONTAL" insets="2,2,2,2"
                weightx="1" gridx="0" gridy="0"/>
            <constraints fill="NONE" insets="2,2,2,2" weightx="2"
                gridx="1" gridy="0" anchor="WEST"/>
        </editor>
    <editor macro="list" label="List">
        <label-constraints fill="HORIZONTAL" insets="2,2,2,2" weightx="1"
            gridx="0" gridy="1"/>
        <constraints fill="NONE" insets="2,2,2,2" weightx="2" gridx="1"
            gridy="1" anchor="WEST"/>
        </editor>
    </editor>
</screen>
<macro name="aggregate" type="composite">
    <vector-property name="groupComponents">
        <vector-elem>text</vector-elem>
        <vector-elem>list</vector-elem>
    </vector-property>
    <property name="selectedMacro">text</property>
    
    <macro name="text" type="varname"/>
    <macro name="list" type="combo-box">
        <vector-property name="listLabels">
            <vector-elem>Option A</vector-elem>
            <vector-elem>Option B</vector-elem>
            <vector-elem>Option C</vector-elem>
        </vector-property>
        <vector-property name="listValues">
            <vector-elem>option_a</vector-elem>
            <vector-elem>option_b</vector-elem>
            <vector-elem>option_c</vector-elem>
        </vector-property>
        <property name="listSelectedValue">option_b</property>
    </macro>
</macro>
<text>
#if ($aggregate.selectedMacro == "text")
Value of text is $aggregate.getMacro("text").
#else
Value of list is $aggregate.getMacro("list").selectedValue.
#end
</text>
</template>
Now the boxes appear as option buttons, as shown in Figure 26.
Figure 26. Rule wizard example 4
Notice that validation occurs only on the selected macro. For example, select an option in the List box while leaving the Text box empty. Notice that the wizard does not display any error message when you click Finish.
Note: Watch for the if construct in the Velocity language used in the code generation portion in order to display the macro chosen by the user.