Show Table of Contents
19.6. HelloWorld Example: Rule "Hello World"
rule "Hello World"
dialect "mvel"
when
m : Message( status == Message.HELLO, message : message )
then
System.out.println( message );
modify ( m ) { message = "Goodbye cruel world",
status = Message.GOODBYE };
end- The LHS (after
when) section of the rule states that it will be activated for eachMessageobject inserted into the Working Memory whose status isMessage.HELLO. - Two variable bindings are created: the variable
messageis bound to themessageattribute and the variablemis bound to the matchedMessageobject itself. - The RHS (after
then) or consequence part of the rule is written using the MVEL expression language, as declared by the rule's attributedialect. - After printing the content of the bound variable
messagetoSystem.out, the rule changes the values of themessageandstatusattributes of theMessageobject bound tom. - MVEL's
modifystatement allows you to apply a block of assignments in one statement, with the engine being automatically notified of the changes at the end of the block.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.