Hi everybody,
short: is there a way to have an automatic counter for the RHS of a rule when inserting
several objects in one rule?
Long:
I use drools with a DSL to insert items for a frontend dropdown box. The generated rule is
e.g. like the following one:
rule "testRule_H"
dialect "mvel"
when
SomePartOfMyModel( someField == "H" )
then
DropDownItem fact1 = new DropDownItem(); fact1.setLabel( "My
Label 1" ); fact1.setValue( "B" );
insert (fact1);
DropDownItem fact1 = new DropDownItem(); fact1.setLabel( "My
Label 2" ); fact1.setValue( "A" );
insert (fact1);
This works nicely and I get all the items. The problem I have is with the sorting. Users
use Guvnor to edit the available items for the dropdown box, so they add and remove items
from the RHS. Since I retrieve those objects from the knowledge base in my java code like
this:
Collection<FactHandle> handles = statefulKnowledgeSession.getFactHandles(new
ClassObjectFilter(DropDownItem.class));
for (FactHandle handle : handles) {
DropDownItem selectItem = (DropDownItem)
statefulKnowledgeSession.getObject(handle);
...
I think I cannot be sure about the order the objects are retrieved (it's a collection,
no guaranteed sorting!). So, I sort the DropDownItems alphabetically by their value.
My question now is, as stated above: How can I implement a counter which I can use in the
facts being inserted to keep my inserted facts (DropDownItems) in the same order as they
are inserted?
Thanks in advance
Dominik
…………………………………………………………………
mit freundlichen Grüßen / kind regards
Dominik Sandjaja
Fon: +49 (0) 203 60878 183
Fax: +49 (0) 203 60878 222
e-mail: dominik.sandjaja(a)it-motive.de
it-motive AG
Zum Walkmüller 10-12
47269 Duisburg
info(a)it-motive.de
http://www.it-motive.de
……………………………………………………………………
Vorsitzender des Aufsichtsrats: Dipl.-Ing. Klaus Straub
Vorstand: Horst-Dieter Deelmann (Vors.), Matthias Heming, Christoph Tim Klose
HRB 9207, Amtsgericht Duisburg