Reputation: 454
I have problems in add instances to list in RHS of rule.
There're two classes shown as below:
class Person {
private java.lang.Integer age;
private java.lang.String name;
}
class A {
private java.util.List<Person> persons;
private java.util.List<Person> selectedPersons;
}
In the following rule, I want to put person with age larger than 30 into selectedPersons.
rule "test"
when
$a:A()
$p : Person(age > 30) from $a.persons
then
$a.getSelectedPersons().add($p);
end
It works in eclipse, with Drools plugin; but it doesn't after deploying to KIE server. What I get is the instance reference only. Any ideas?
Also, I wonder why KIE server throw java.lang.NoSuchMethodError Exception when I add following constructor to Person class, while workbench can build and deploy the rule successfully:
public Person(Person p)
{
this.name = p.name;
this.age = p.age;
}
Upvotes: 0
Views: 2463
Reputation: 454
I should add constructor mentioned in the question. BTW, if there's a Date attribute in Person class, it should be copied or cloned, see here.
Hmm, after deleting the container and create it again, exception disappeared. I don't know if it's a problem of drools (Version 6.2), or a problem of process of setting up drools.
Upvotes: 0
Reputation: 1552
The class should look like this:
class A {
private java.util.List<Person> persons;
private java.util.List<Person> selectedPersons;
//First create getter, setter for the lists.
void addToList(Person item)
{
selectedPersons.add(item);
}
}
And the rule should look like this:
rule "test"
when
$a:A()
$p : Person(age > 30) from $a.persons
then
$a.addToList($p);
end
Upvotes: 1