Is B name of the class? If so it should be name of the variable not the class name.
As you are using 4.0.7 the above rule can be written as:

rule "test"
       salience 20
       no-loop true
       when
               $a:A( $b : b);
               B(X=="testValue") from $b
            // eval (b.X == "testValue"); using eval is not a good idea. There might be a performance hit.
           
       then
               $a.setSomething();
               update($a);
       end

Regards,
sudhir

On Mon, Feb 23, 2009 at 5:59 PM, D1vy@@Ind1@ <divya.rajendranath@gmail.com> wrote:

Sudhir,
Thanks for the information ...

To give more data..
I am using drools 4.0.7 version.

I have appropriate setters and getters in all my classes A, B, Z.

My drools file look like this:

rule "test"
       salience 20
       no-loop true
       when
               $a:A( b : B);
               eval (b.X == "testValue");
       then
               $a.setSomething();
               update($a);
       end

When I run this rule, it says

Unable to create Field Extractor for 'B' : [Rule name=test,
agendaGroup=MAIN, salience=20, no-loop=true]
org.drools.RuntimeDroolsException: org.drools.RuntimeDroolsException:
Field/method 'B' not found for class 'com.test.java.A'
Rule Compilation error : [Rule name=test, agendaGroup=MAIN, salience=20,
no-loop=true]
       Rule_test_0.java (8:323) : b.X cannot be resolved to a type
E

I have double checked if there was any typos in defining my fields, and
there exists no problem due to typos.

Could you please throw light on this exception ?


Thanks
-D




D1vy@@Ind1@ wrote:
>
> Hi,
>
> I am planning to use Drools - JBoss Rules Engine. My requirement is to
> disburse mails from my application to different groups based on various
> criteria. I want to use Drools here.
>
> My object structure is as follows:
>
> class A{
>
> String B = "";
>
> B b;
>
> C c;
> }
>
> Hence Obj A has embedded objects within it, and obj B and C further has
> embedded objects.
>
> class B {
>
> String X;
>
> Z z;
>
> }
>
> class Z{
>
> String t;
>
> String s;
>
> }
>
> The decision on sending the mails based on the fields in embedded objects
> of
> A. I pass instance of A to Drools
>
> Format of drl file:
>
> package...;
>
> import ..;
>
> rule "Test"
>
> when $a:A(B(Z(s == "testvalue")))
>
> then
>
> $a.setSomething();
>
> update($a);
>
> end
>
> I wanted to know if this (accessing fields in embedded/child object) is
> feasible with Drools.
>
> I get an error saying "UNable to compile myfile.drl when i try to fo this.
>
> Could some one look into this issue and let me know the reason for this ?
>
>
>
> Thanks
>
> -D
>
> _______________________________________________
> rules-users mailing list
--
View this message in context: http://www.nabble.com/Help-on-using-Drools-with-embedded-objects-tp22158087p22160635.html
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list