I think I've solved this. You have to fire the property change event *AFTER* you change the underlying property. As long as session.update() is called *AFTER* the value has changed, things seem to work correctly.
Does this sound like a reasonable solution? I think I saw in the documentation (what little I could find on this particular subject) that the property event was triggered before the actual value changed. Jason Smith ________________________________________ From: rules-users-boun...@lists.jboss.org [rules-users-boun...@lists.jboss.org] On Behalf Of Jason Smith [jsm...@infotrustgroup.com] Sent: Friday, November 27, 2009 10:13 AM To: Rules Users List Subject: Re: [rules-users] Updates with property change on facts. How??? The Update command appears to be processed in org.drools.process.commands.UpdateCommand. It's doing the update the same way I am. Why does this code work when Drools uses it, and it doesn't work for me? package org.drools.process.command; import org.drools.reteoo.ReteooWorkingMemory; import org.drools.runtime.rule.FactHandle; public class UpdateCommand implements Command<Object> { private FactHandle handle; private Object object; public UpdateCommand(FactHandle handle, Object object) { this.handle = handle; this.object = object; } public Object execute(ReteooWorkingMemory session) { session.update( handle, object ); return null; } public String toString() { return "session.update( " + handle + ", " + object + " );"; } } Jason Smith ________________________________________ From: rules-users-boun...@lists.jboss.org [rules-users-boun...@lists.jboss.org] On Behalf Of Jason Smith [jsm...@infotrustgroup.com] Sent: Friday, November 27, 2009 10:04 AM To: Rules Users List Subject: Re: [rules-users] Updates with property change on facts. How??? Here is a twist. If I call "update($fact)" explicitly in the rule, the rule is NOT called twice. Can someone point me to the code used by "update($fact)"? Maybe I can figure out what I did wrong to cause the rule to fire incorrectly a second time. Jason Smith ________________________________________ From: rules-users-boun...@lists.jboss.org [rules-users-boun...@lists.jboss.org] On Behalf Of Jason Smith [jsm...@infotrustgroup.com] Sent: Friday, November 27, 2009 9:54 AM To: Rules Users List Subject: [rules-users] Updates with property change on facts. How??? I implemented the following listener for my bean and I am calling .update() directly on the StatefulKnowledgeSession. QUESTION 1: Is there a better way? The old API supported .insert(fact,boolean). The new one does not. I am not finding any documentation that explains the new API (version 5.0.1). QUESTION 2: Why is this calling my rule twice? The rule is getting called twice, and the second time it's called, the entry conditions are invalid! That is, I changed the bean in a way that invalidates the WHEN condition. The rule still gets called twice. How do I even begin to go about troubleshooting this? This same behavior was happening with Drools 4 and the old API as well. private class InnerPropertyChangeListener implements PropertyChangeListener { private final InternalFactHandle factHandle; private final Object fact; private final StatefulKnowledgeSession session; public InnerPropertyChangeListener(InternalFactHandle factHandle, Object fact, StatefulKnowledgeSession session) { this.factHandle = factHandle; this.fact = fact; this.session = session; } @Override public void propertyChange(PropertyChangeEvent evt) { System.out.println("****** UPDATING " + evt.getPropertyName() + ": " + "\n NEW: " + StringUtil.indent(BeanUtil.printObject(evt.getNewValue()),16) + "\n OLD: " + StringUtil.indent(BeanUtil.printObject(evt.getOldValue()),16)); if((evt.getNewValue() == null && evt.getOldValue() != null) || !evt.getNewValue().equals(evt.getOldValue())) { session.update(factHandle, fact); } } } Jason Smith _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users