Hi,

I can't seem to make this syntax work in Drools 4.0.2. Pls. see my sample
code below.
________________________________________
class MyClass {
        String id;
        String name;

        MyClass(String id, String name){
                this.id = id;
                this.name = name;
        }
        :
        getter, setter methods
        :
}

MyClass obj = new MyClass("1"", "name");

TreeMap<String, MyClass> mapOfObj = new TreeMap<String, MyClass>();
mapOfObj.put("keyOfObj", obj);
________________________________________

DRL file
-------

global java.util.TreeMap mapOfObj;

rule chkobj
when
        obj : MyClass(mapOfObj["keyOfObj"].id == "1");
        eval(obj.getName() == "name");
________________________________________

I'm getting this error: org.drools.RuntimeDroolsException:
java.lang.NullPointerException
                            at
org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)

Is my syntax correct and has someone used this in 4.0.2 or should I move on
to Drools 4.0.3? Thanks in advance.

Regards,

shaz


Edson Tirelli-3 wrote:
> 
>    Denis,
> 
>    If you are using latest build from trunk (I'm not sure it already works
> in MR3), you can use a simplified MVEL syntax:
> 
> when
>     Person( address["business"].phone == "99999999" )
> then
>     ...
> end
> 
>    Although, the above will be converted into an inline-eval. Not as bad
> as
> a top level eval, but still more costly then using regular fields.
> 
>    []s
>    Edson
> 
> 2007/7/19, Ryan, Dennis (Dennis) <[EMAIL PROTECTED]>:
>>
>>  We are using Maps (HashMaps) in our rules and the only way we have found
>> to access keys and values in the Map in the "when" clauses is thru use on
>> eval() which I know is a big no-no by rules purists. Is there a better
>> way,
>> maybe some shorthand I'm not familiar with to deal with Maps in the when
>> clause?
>>
>>
>>
>> Thanks,
>>
>> Dennis
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
> 
> 
> -- 
>   Edson Tirelli
>   Software Engineer - JBoss Rules Core Developer
>   Office: +55 11 3529-6000
>   Mobile: +55 11 9287-5646
>   JBoss, a division of Red Hat @ www.jboss.com
> 
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 
[EMAIL PROTECTED]
-- 
View this message in context: 
http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-rules-tf4112197.html#a13524477
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to