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