[rules-users] Can we return values from rules to java ?

FrankVhh frank.vanhoenshoven at agserv.eu
Wed Dec 29 06:32:22 EST 2010


Hi,

I want to correct myself on my point about passing the variable to JAVA. You
should probably add an array of strings to some object and for each rule,
add a string to the list.

rule "Hello World"
	when
		m : Message( conditions )
	then
                // 
		m.addRuleToArray( "Hello World" );
		update( m );
end

In your Java code, add an array of strings (or integers or whatever,...),
write a function to add information to the array and just call that function
from within your rule. All fired rules will be added to the array and will
be available to you in Java.

regards,
Frank


FrankVhh wrote:
> 
> Hi Shobbit,
> 
> Being an inexperienced user myself, I am nevertheless going to try to help
> you out.
> 
> I am not sure whether I understand the question right. All of the fired
> rules should have generated a match at some point. So, the answer to the
> question: which of the fired rules was matched, is: "All of them".
> 
> If you just want to know which rules were fired, then this shouldn't be
> too difficult to achieve. When a rule is matched on the left hand side,
> the actions on the right hand side will be executed. Just add something in
> the RHS to pass information to you.
> 
> If you want the information in your java code: 
> -add a stringvariable to your javacode and, for each rule, decide which
> value to assign to this variable.
> 
> If you just want to see the info yourself, there are a number of ways to
> achieve this:
> 1-Add a System.out.println("Rule fired matched and fired") in each rule.
> 2-Enable logging and read the logfile.
> 3-When debugging your code, you should also be able to see the activated
> rules.
> 
> Regards,
> Frank
> 
> 
> Shobhit1 T wrote:
>> 
>> Hi, 
>> 
>> I want to know which of the fired rules was matched. Is there a way to 
>> find that out or return a value from drl to java file that can indicate 
>> which rule was matched? 
>> Thanks 
>> 
>> Shobhit
>> 
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> 
>> 
> 
> 

-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Can-we-return-values-from-rules-to-java-tp2162152p2162383.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list