Wiki source code of How to Write D2W Rules
Version 4.1 by Ravi Mendis on 2009/11/12 16:51
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | The quick answer is... | ||
2 | |||
3 | == Use Convention Over Configuration == | ||
4 | |||
5 | We may use [[convention over configuration>>http://en.wikipedia.org/wiki/Convention_over_configuration]] to set up **default** D2W rules. | ||
6 | |||
7 | In D2W, rules with a higher priority take precedence. | ||
8 | e.g: | ||
9 | |||
10 | {{code}} | ||
11 | |||
12 | 100: entity.name = 'Father' and task = 'edit' and propertyKey = 'firstName' => componentName = "D2WEditString" | ||
13 | |||
14 | {{/code}} | ||
15 | |||
16 | The above will override, or take precedence over the following: | ||
17 | |||
18 | {{code}} | ||
19 | |||
20 | 75: task = 'edit' and propertyKey = 'firstName' => componentName = "D2WEditString" | ||
21 | |||
22 | {{/code}} | ||
23 | |||
24 | We may exploit this feature of D2W to set up a set of rules as conventions or defaults. | ||
25 | As an example, the above rule may be set up to be a default for the editing of the key ##firstName## instead of having to define separate rules for every entity that has a ##firstName##. In other words the one rule (above) replaces the following three rules: | ||
26 | |||
27 | {{code}} | ||
28 | |||
29 | 100: entity.name = 'Father' and task = 'edit' and propertyKey = 'firstName' => componentName = "D2WEditString" | ||
30 | 100: entity.name = 'Mother' and task = 'edit' and propertyKey = 'firstName' => componentName = "D2WEditString" | ||
31 | 100: entity.name = 'Child' and task = 'edit' and propertyKey = 'firstName' => componentName = "D2WEditString" | ||
32 | |||
33 | {{/code}} | ||
34 | |||
35 | In this manner we can keep the number of D2W rules down to a minimum - which vastly improves maintainability. | ||
36 | |||
37 | {{info title="Rule of Thumb"}} | ||
38 | |||
39 | Set a lower priority to generic rules. | ||
40 | |||
41 | {{/info}} |