In my opinion, the best technique is to implement the fact classes in
a way that avoids null as a return value for any attribute. In your
case, the caveat might be set to the empty string ("") and that would
solve your problem nicely.
-W
On 30/01/2012, dunnlow <dunnlow(a)yahoo.com> wrote:
Hi,
I'm using a template to validate information in my POJO. I've got a row for
the different valid possibilities.
My template rule (in guvnor) looks like:
WHEN
There is a MyBean[$mb] with:
itemname matches templateItemName
cost greater than templateCost
caveat matches templateCaveat
THEN
. 8<
(I have columns in my template for templateItemName, templateCost and
templateCaveat).
Almost always, I don't care about the value in $mb.caveat, so I have a
".*"
in the entry for that row. This works fine as long as $mb bean has a caveat
(ie, $mb.caveat !=null). But when caveat is null the check for caveat
matches templateCaveat (where templateCaveat = ".*") fails. I tried the
regex ".*|null" but that doesn't work either, which I suppose isn't so
surprising (although I never see a NPE error msg).
Modifying the template like this doesn't work:
itemname matches templateItemName
cost greater than templateCost
any of the following:
caveat==null
caveat matches templateCaveat
because when a null valued caveat comes in, this then matches both the rule
I want to fire and the lone one or two with a constraint on that field
(something other than ".*"). I know I can set the salience so that the rows
with ".*" fire first, but that seems REALLY ugly.
I also considered putting in a rule with a high salience that adds a dummy
caveat if one doesn't exist, but this still seems somewhat ugly.
What I'd like to do is have a constraint such as: if caveat matches
templateCaveat or (if caveat is null and templateCaveat does not match ".*")
Does anyone have any insight about the best way to implement this?
Thank you,
-J
--
View this message in context:
http://drools.46999.n3.nabble.com/null-POJO-attribute-causing-template-is...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users