Print
Basic Syntax

MVEL is an expression language based on Java-syntax, with some marked differences specific to MVEL.  Unlike Java however, MVEL is dynamically typed (with optional typing), meaning type qualification is not required in the the source. 

An MVEL expression can be as simple as a single identifier, or as complicated as a full blown boolean expression with method calls and inline collection creations.

Simple Property Expression

user.name

In this expression, we simply have a single identifier (user.name), which by itself, is what we refer to in MVEL as a a property expression, in that the only purpose of the expression is to extract a property out of a variable or context object.  Property expressions are one of the most common uses, allowing MVEL to be used as a very high performance, easy to use, reflection-optimizer. 

MVEL can even be used for evaluating a boolean expression:

user.name == 'John Doe'

Like Java, MVEL supports the full gambit of operator precedence rules, including the ability to use bracketing to control execution order.

(user.name == 'John Doe') && ((x * 2) - 1) > 20




Returned Values

MVEL is designed to be an integration language at it's core, allowing developers to provide simple scripting facilities for binding and logic. As such, MVEL expressions use a last value out principle. This means, that although MVEL supports the return keyword, it is almost never needed. For example:

a = 10;
b = (a = a * 2) + 10;
a;

In this particular example, the expression returns the value of a as it is the last value of the expression. It is functionally identical to:

a = 10;
b = (a = a * 2) + 10;
return a;
Powered by Atlassian Confluence