最近我正在使用drools,我想对某些对象进行一些特殊检查.我需要when在规则部分使用函数,但是我收到了错误.例:
function boolean newFunction(int a){
if(a>0)
return true;
else
return false;
}
rule "new rule"
salience 100
dialect "mvel"
when
eval(newFunction(1))
then
System.out.println("OK");
end
Run Code Online (Sandbox Code Playgroud)
我得到的错误总是:
unable to resolve method using strict-mode: java.lang.Object.newFunction(java.lang.Integer)
Run Code Online (Sandbox Code Playgroud)
drools是否没有支持when部分中的功能?
谢谢!
情况很容易。我创建了一个规则文件:
package org.domain.rules;
dialect "mvel"
import eu.ohim.fsp.core.configuration.domain.xsd.Section;
global java.lang.String sectionName;
rule "rule 1"
salience 1000
when
Section($name : nameOfTheSection)
eval(sectionName == null)
then
System.out.println("Section: " + $name+ "("+$name.length()+")");
System.out.println("Section Name: " + sectionName + "("+sectionName.length()+")");
System.out.println("Mark Details: " + sectionName.equals(null));
end
Run Code Online (Sandbox Code Playgroud)
在触发规则之前,我添加了带有有效coreName和全局变量的Section对象:
public void fireInserted(Section section1) {
kstateful.insert(section1);
kstateful.setGlobal("sectionName", new String("markudetails"));
kstateful.fireAllRules();
}
Run Code Online (Sandbox Code Playgroud)
结果是:
Section: markudetails(12)
Section Name: markudetails(12)
Mark Details: false
Run Code Online (Sandbox Code Playgroud)
问题:怎么可能?在什么时候部分为空,然后部分不为空!