[rules-users] Trouble adding things to a list

Grimshaw, Jeffrey Jeffrey.Grimshaw at greenpoint.com
Sat Mar 10 21:38:50 EST 2007


I found the problem and it had nothing to do with the rules (or not much
anyway).  All the rules are operating on the same instance of document.
The addDocuments method is passed that instance and it is added to an
array _by reference_.  Thus, when the next rule comes along and modifies
the document, it modifies the same instance that is referenced in the
array and the values change there.

I fixed it by simply modifying the addDocuments method to create a new
document instance with a copy constructor and then add the _local_
instance to the array, rather than the one passed in. 

Works great!

--Jeff

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Grimshaw,
Jeffrey
Sent: Saturday, March 10, 2007 4:31 PM
To: Rules Users List
Subject: [rules-users] Trouble adding things to a list 

Hi all.  I've got some rules that are supposed to add documents to a
list that is then returned to the caller.  Each rule sets some
properties on a document and then adds it to the list.  The correct
number of objects are being added to the list, but each object has the
attributes that were set in the first matching rule.  It seems as if the
properties on the object can be set only once and cannot be changed by
subsequest rules.

Here's the comlete DRL:

package com.mycompany.rules.documentlist; #generated from Decision Table
import com.mycompany.rules.documentlist.*;
#From row number: 11
rule "DocumentList_11"
	
	when
		document : DocumentAttributes()
		docList : DocumentList()
	then
		document.setAllowActivityCompletion(false);
		document.setName("Document 1");
		document.setTypeID(100);
		document.setHelpFile("Help File");
		docList.addDocuments(document);
end

#From row number: 12
rule "DocumentList_12"
	
	when
		document : DocumentAttributes()
		docList : DocumentList()
	then
		document.setDisplayDocument(true);
		document.setName("Document 2");
		document.setTypeID(101);
		document.setHelpFile("Help File");
		docList.addDocuments(document);
end

As you can see, the DRL was generated from a decision table, but I don't
think that has anything to do with the behavior I'm seeing.  The
document bound variable is set correctly and added to the list in the
first rule, but the second rule adds the same document as was added in
the first rule.

Any suggestions as to what is going on here would be much appreciated.
Is it even possible to get there from here?  I tried setting
Sequential=true on the decision table, but that does not help.

Thanks,

Jeff Grimshaw
Sr. Programmer/Analyst
Green Point Mortgage



_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




More information about the rules-users mailing list