Any null value encountered by a targeter is interpreted to mean “this value is unknown.” If any such unknown values are encountered during rule evaluation or query execution, the corresponding repository items are not included in the targeting results. For example, consider the rule
<rule op=eq>
<valueof bean="Profile.ageGroup">
<valueof target="ageGroup">
</rule>
This rule might encounter null values in two cases:
If
Profile.ageGroup
evaluates to null, we deduce that the user did not specify his age, and hisageGroup
is therefore unknown. In this case, no content should be returned by this rule.If
Profile.ageGroup
evaluates toTeenagers
, the only items returned from the repository query should be the ones withageGroup
equal toTeenagers
. A content item with a nullageGroup
value should not be returned, since itsageGroup
property is considered to be unknown.
The less intuitive case is the case with rules that use negative rule operators, such as neq
. For example:
<rule op=neq>
<valueof bean="Profile.ageGroup">
<valueof target="forbiddenAgeGroup">
</rule>
Here again,
If
Profile.ageGroup
evaluates to null, theageGroup
is unknown, and no content is returned.If
Profile.ageGroup
evaluates toTeenagers
, the only items returned from the repository query should be the ones which have theforbiddenAgeGroup
property set to something other thanTeenagers
- but not null. Items whoseforbiddenAgeGroup
property is null should not be returned, since theirforbiddenAgeGroup
is unknown.
The principle behind this treatment of null values is that when the user doesn’t specify a value for one of his properties, or when the content creator does not specify a value for one of the content attributes, that unspecified value in actuality may or may not match the rule condition we are trying to satisfy. If there is a possibility that the condition may not be satisfied, we always err on the conservative side and do not include the questionable people or content. If you want to include items with null values, then add a term to the rule with an or rule operator, like this:
<rule op=or>
<rule op=eq>
<valueof bean="Profile.ageGroup">
<valueof target="ageGroup">
</rule>
<rule op=isNull>
<valueof target="ageGroup">
</rule>
</rule>
This rule returns all content items whose ageGroup
attribute matches the profile’s ageGroup
, and also all content items whose ageGroup
attribute is null.