Extended Action Language (EAL) lets you write actions that change model data, and is for MDriven developers configuring actions, ViewModels, class methods, and state-machine effects.
EAL extends OCL with imperative operations. Use OCL when you need to calculate, navigate, filter, compare, or constrain values without changing data. Use EAL when the expression must produce an effect, such as assigning an attribute, creating or deleting an object, changing a collection, or executing an action.
When to use EAL
Use EAL in places where MDriven executes an action expression.
| Location | What EAL acts on | Example use |
|---|---|---|
| An action's ExecuteExpression | The action context | Set values, create objects, or call model methods when a user runs an action. |
| An action column's Execute expression in a ViewModel | The ViewModel context and its variables | Update the object selected in a grid. |
| A class method implementation | The receiving object, available as self
|
Implement behavior that changes an instance of the class. |
| A state-machine effect | The object undergoing the state change | Set a date or update related data when a transition occurs. |
For the full description of action types and their contexts, see Documentation:Actions and Training:What an Action can do.
Start with the expression context
The context determines which objects and variables your EAL expression can reach.
- In a ClassAction or class method,
selfis the object of the class. For example,self.SomeInt := 27changes theSomeIntattribute of that object. - In a ContextAction, you can use the variables defined by the ViewModel context. These include variables named
vCurrent_TheViewModelClassName, which follow the user's current selection. - In a GlobalAction, the context is null. Start from a model class, for example by using
X.allinstancesorX.Create.
Before writing an action, identify the object that should change and write the expression from that context. Do not assume that self is available in every action type.
Core EAL syntax
Assign with :=
Use := to assign a value. Use = to compare values.
self.SomeInt := 27
self.SomeInt = 27
The first expression changes SomeInt. The second expression evaluates whether SomeInt equals 27.
Sequence statements with ;
Use a semicolon to run multiple statements in order. The statements execute from left to right.
self.SomeDateTime := DateTime.Now;
self.SomeInt := 27;
self.SomeString := self.SomeDateTime.ToString('yyyy-MM-dd')
This action stores the current date and time, assigns an integer, and then formats the date into a string.
A semicolon is a separator between statements, not a terminator after the final statement. Do not add a trailing semicolon.
'a string'; 0
The expression above has type integer because 0 is its final statement. In contrast, the following is invalid because the parser expects another statement after the final separator:
'a string'; 0;
Create objects
Use Create on a class to create an object.
Thing.Create
You can then use EAL assignment and collection operations to initialize or connect the created object. See the EAL object-lifecycle operators for create, delete, and setToNull.
OCL and EAL: choose the correct expression type
| Need | Use | Example |
|---|---|---|
| Calculate or test a value without changing model data | OCL | self.SomeInt = 27
|
| Change data or perform an operation | EAL | self.SomeInt := 27
|
| Decide whether an action is available | OCL in the action's EnableExpression | self.oclIsInState(#Deletable)
|
| Perform work when an action runs | EAL in the action's ExecuteExpression | self.SomeInt := 27
|
An EnableExpression must evaluate to Boolean and must not have side effects. Put assignments, creation, deletion, and other changes in ExecuteExpression instead.
Build an action expression
- Choose where the action runs: an action, a ViewModel action column, a class method, or a state-machine effect.
- Identify the available context. Use
selffor an object-rooted expression; use the ViewModel variables for a context action; start from a class in a global action. - Write the change with
:=, or use an EAL operation such asCreate. - Add
;only between statements when the action has more than one step. - Keep the final statement free of a trailing semicolon.
- Put availability rules in the action's OCL EnableExpression, not in its EAL ExecuteExpression.
Common mistakes
- Using
=for assignment:=compares; use:=to change a value. - Adding a final semicolon: an EAL sequence must end with a statement, not with
;. - Putting data changes in EnableExpression: EnableExpression is OCL and must be side-effect free.
- Using the wrong root object: global actions have no
selfcontext; start from a class or use the context variables available to the action. - Expecting a ViewModel/Context action to work in a table like a class action: ViewModel/Context actions display as disabled in tables, while class actions and ViewModel action columns with EAL work as expected. See Documentation:Web client actions in tables.
More EAL operations
EAL also includes flow control, collection manipulation, persistence, navigation, import and export, external communication, and server-related operations. For example, EAL provides whentrue, whenfalse, and foreach for flow control; add, remove, and clear for collections; and operations such as Save, Refresh, Search, and ReQuery for persistence work.
When overriding a class method, you can call its superclass implementation with self.base.MethodName. See Documentation:Calling base class for the inheritance example.
