better still using in-line eval:
when $c: Computer(memory!=null memory.value == 128) then doSomething();
The owners / contributers to the drools-expert code base can comment:
Is the check for null necessary when using nested accessors??? Is this
something that the engine can take care during
Is the following rule in-valid?
when
$c: Computer()
eval($c.getMemory().getValue() == 512)
then
System.out.println( THIS IS IT XXX );
___
Can someone help me understand if eval is used incorrectly to invoke the
nested accessor method getValue()? Null pointer
Modifying the eval expression to include a check for NULL got it working:
when
$c: Computer()
eval( $c.getMemory()!=null $c.getMemory().getValue().equals(512) )
then
System.out.println( THIS IS IT XXX );
end
Visu Nageswaran wrote:
Hello, I am posting a simpler version of
Hello, I am posting a simpler version of the actual requirement:
Class Computer has a field 'memory' of the enum type 'Memory' which is
defined over integer values
- - - - - - - - - -
public enum Memory{
MEM1(512), MEM2(1024), MEM3(2048);
public int value;
Memory(int i){this.value = i;}
I was able to achieve this using a join-column in the decision table
equivalent to the below rule:
WHEN $m: Memory(value == 512) $c: Computer(memory == $m)
THEN modify($c){ setPrice(100) };
However, a Memory instance needs to be inserted into the session. For every
discrete valued field, it
Are you sure you have to have a Memory object inserted as a fact ?
Don't this rule works (not tested and I'm so not a drools expert)
rule memory
when
$c : Computer(memory == MEM1 || memory == MEM2 || memory == MEM3)
then
modify($c) { setPrice(MEM1.getValue() };
end
On Wed, 8 Jul 2009
Erik,
Thanks for your comment. In your suggestion, you have compared the memory
field with MEM.CONST1 and are setting the price to MEM.value.
But, the requirement is to restrict the field memory with the value of
CONST1 (like 512, 1024, 2048) in the decision table and based on that set
the price