What you are trying to do can be accomplished in CVP 9 using a custom validator (older versions do not have this capability). The following code snippet should do what you want. The way it works is that Setting A is assigned a custom validator that will fail validation if both it and Setting B are left blank.
1public class CustomElement extends ElementBase implements ElementInterface {
2 @Override
3 public Setting[] getSettings() throws ElementException {
4 Setting settingA = new Setting("settingA", "Setting A", "The first setting",
5 Setting.OPTIONAL, Setting.SINGLE, Setting.SUBSTITUTION_ALLOWED, Setting.STRING);
6 Setting settingB = new Setting("settingB", "Setting B", "The second setting",
7 Setting.OPTIONAL, Setting.SINGLE, Setting.SUBSTITUTION_ALLOWED, Setting.STRING);
8
9 // Validate that at least one of Setting A or Setting B has been set
10 settingA.setCustomValidator(new OrValidator(settingB));
11
12 return new Setting[] {settingA, settingB};
13 }
14 // The rest of the class has been omitted
15}
16class OrValidator implements SettingValidator
17{
18 private Setting otherSetting;
19
20 public OrValidator(Setting otherSetting)
21 {
22 this.otherSetting = otherSetting;
23 }
24
25 /**
26 * Validation method for OrValidator.
27 * @param value The setting to validate.
28 * @param setting Contains information about the setting being validated.
29 * @param allSettingParams Contains information about all settings in the custom element, keyed by each setting's real name.
30 * @return A list of error messages to display.
31 */
32 @Override
33 public List<String> validate(String value, SettingParams params,
34 Map<String, SettingParams> allSettingParams)
35 {
36 List<String> errors = new ArrayList<String>();
37
38 SettingParams otherSettingParams = allSettingParams.get(otherSetting.getRealName());
39 if (otherSettingParams != null &&
40 StringUtils.isEmpty(otherSettingParams.getCurrentValue()) &&
41 StringUtils.isEmpty(value))
42 {
43 errors.add("At least one of " + params.getDisplayName() + " or " +
44 otherSettingParams.getDisplayName() + " must be set.");
45 }
46
47 return errors;
48 }