3

All

I want to know that how to define contant variable in jboss drools rule.

So, Admin has to change only one place to modify the configurable value.

Thanks.

MohammedYakub M.
  • 2,893
  • 5
  • 31
  • 42

1 Answers1

4

You´re able to define global variables within a rule. This variable can be filled via Java like this:

public void init() {
        StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();

        String string = "foo";
        // setGlobal 'string' as 'var' in rule
        ksession.setGlobal("var", string);
}

In the rule, this global can be accessed via the 'global' keyword:

global String var;

rule "Test"
    when
        # actual condition 
    then
        # RHS
end
fnst
  • 5,574
  • 4
  • 23
  • 18
  • hey, fnst your are right i can do that way but its not maching with my requirement. i want to initialize constant in rule itself, is that possible ? i searched it on web & forum but could not get any help... – MohammedYakub M. Jun 24 '11 at 04:23
  • Yes, I knew that my answer does not quite apply to your request. But I thought it might help anyway. About a definable constant, unfortunately I do not know anything. – fnst Jun 27 '11 at 06:15