Hi Ali:

Yes, you are right!

 But in Drools’ user guide, it said this:

3.5.4.1. Field Constraints

Field constraints place constraints on the Fact objects for the rule engine to match/select out of working memory. They work comparing/evaluating "field" values from the fact object instances.

A "field" is not a field in the sense of a public or private member of a class. A field is an accessible method. If your model objects follow the java bean pattern, then fields are exposed using "getXXX" or "isXXX" methods (these are methods that take no arguments, and return something). You can access fields either by using the bean-name convention (so "getType" can be accessed as "type").

For example, refering to our Cheese class, the following : Cheese(type == ...) uses the getType() method on the a cheese instance. You can also access non getter methods, like "toString()" on the Object for instance (in which case, you do Cheese(toString == ..) - you use the full name of the method with correct capitalisation, but not brackets). Do please make sure that you are accessing methods that take no parameters, and are in-fact "accessors" (as in, they don't change the state of the object in a way that may effect the rules - remember that the rule engine effectively caches the results of its matching inbetween invocations to make it faster).

 

But I find it couldn’t work at all! Do I have a wrong understand?

Do you have some thoughts?

Thanks!


发件人: Ali Abdel-Aziz Ali [mailto:[EMAIL PROTECTED]
发送时间: 2006年11月9 18:10
收件人: [email protected]
主题: Re: [drools-user] Unable to create Field Extractor

 

Hi zhang,

remove the get and just use the field name as follows

rule "Your First Rule"
   
when
        RuleTest(name == 1)
       
#conditions
   
then
       
#actions

end

 

On 11/9/06, 张茂森 < [EMAIL PROTECTED]> wrote:

Hi all:

I am a new comer to Drools. After I read the user guide, and I've write my HelloWorld, but I got the error like this

'Unable to create Field Extractor', when I use getXXX function name nor xxxx variable name.

BTW, my IDE is eclipse.

This is my code and rule:

Code:

package com.sample;

 

public class RuleTest {

    public int name;

    public int getName(){

        return name ;

    }

 

}

Rule:

#created on: 2006-11-9

package rules

import com.sample.RuleTest;

 

rule "Your First Rule"

   

    when

        RuleTest(getName == 1)

        #conditions

    then

        #actions     

end

 

 




--
Ali Abdel-Aziz
http://www.aliabdelaziz.com
http://aabdelaziz.blogspot.com

Reply via email to