Try to declare static all yours methods...:) Ricardo
----- Original Message ----- From: "Angus Helm" <[EMAIL PROTECTED]>
To: <[email protected]> Sent: Friday, February 03, 2006 11:59 AM Subject: [drools-user] Can't use functions in conditions? I've read in the mailing list archives that you should be able to use functions declared in <java:functions> tags within a condition. However, I've been struggling for several hours now trying to get it to work. From looking at the debug output, the rule is simply never firing. Here's my code: <!-- ******************************* Functions ****************************** **--> <java:functions> public static java.util.Map totalHoursMap = new java.util.HashMap(); public Integer getTotalHours(User user){ if(totalHoursMap.containsKey(user)){ Integer inte = (Integer) totalHoursMap.get(user); System.out.println ("Found: " + inte); return inte; } else { System.out.println("Not found."); return new Integer(0); } } public void setTotalHours(User user, int hours){ totalHoursMap.put(user, new java.lang.Integer(hours)); } </java:functions> <!-- ****************************** Rules *************************************--> <rule name="Count Hours" salience="200"> <parameter identifier="shift"> <class>Shift</class> </parameter> <parameter identifier="user"> <class>User</class> </parameter> <java:condition> shift.getUser().equals(user) </java:condition> <java:condition> user.getMaxHours() != null </java:condition> <java:consequence> int newHours = getTotalHours(user).intValue(); newHours += (int)(shift.getEndTime().intValue() - shift.getStartTime().intValue()) / 100; setTotalHours(user, newHours); System.out.println(user.getName() + " has worked " + newHours + " hours."); </java:consequence> </rule> <rule name="Maximum Hours" salience="100"> <parameter identifier="user"> <class>User</class> </parameter> <java:condition> user.getMaxHours() != null </java:condition> <java:condition> user.getMaxHours().compareTo(getTotalHours(user)) < 0 </java:condition> <java:consequence> System.out.println(user.getName() + " has worked " + (getTotalHours(user).intValue() - user.getMaxHours().intValue()) + " more hours than is allowed."); </java:consequence> </rule> I originally had the totalHoursMap as application data, but that was causing different problems. The first rule fires normally. I've been trying various ways of writing the condition, as well as accessing the totalHoursMap directly, both when it is application data and a static variable. Any help?
