You can expose class actions from a related object while keeping the current object as the row shown in a ViewModel grid; this is for ViewModel designers working with nested ViewModels, especially association objects.
What Act As For Actions does
Act As For Actions is a property on a ViewModel nesting. It contains an OCL navigation expression that starts at the object represented by that nesting and identifies the object whose class actions should be offered.
The nesting still displays its own objects. Act As For Actions changes only the object used when MDriven decides which class actions to expose for a row.
For example, a grid can display ProductSale rows because they contain the precise sale-specific information that users need. If a ProductSale has a related Category, set Act As For Actions to:
self.CategoryThe grid continues to show ProductSale. Class actions defined on Category, such as ShowCategory, become available in the ProductSale row context and execute on the related Category object.
When to use it
Use Act As For Actions when the object you need to display is not the object that owns the reusable behavior.
A common case is an association object, also called a link object. Consider a link class B between classes A and C:
- Display
Bin a grid when users need the link-specific precision, such as attributes held by the association. - Navigate from
Bto one end of the association, for exampleself.A. - The grid can then expose the actions defined on
Awithout duplicating them as actions onB.
This is also useful when the related class has actions implemented differently for several subclasses. Forwarding to that related object lets MDriven resolve the appropriate class action from the actual related type rather than requiring the link object to reproduce that type-specific logic.
Configure a nesting
- In MDriven Designer, open the ViewModel that contains the grid or other nesting.
- Select the nesting whose objects should continue to be displayed. For example, select the
ProductSalenesting. - In the nesting's Act As For Actions property, enter an OCL expression that navigates from the nesting object to the action-owning object.
- Ensure that the expression identifies zero or one target object for each displayed row. For example, use
self.Category, not a navigation that can produce several categories. - Upload or otherwise update the running model, then refresh the client and select a row.
- Check the actions available for that row. The class actions of the related target object should now be available. Configure the view to exclude actions that do not fit that context.
Expression rules
The expression is evaluated with the nesting object as its context. Start the navigation with self and follow associations as needed.
| Situation | Example expression | Result |
|---|---|---|
A ProductSale points directly to one Category.
|
self.Category
|
Category class actions are offered for each ProductSale row that has a Category. |
A link object B points to one A.
|
self.A
|
A class actions are offered while B remains the displayed row. |
| The target is reached through more than one association. | self.Order.Customer.Category
|
Category class actions are offered when the navigation ends in one Category. |
The navigation may contain multiple association steps, but it must resolve to at most one object for a row when an action is executed. A row with no related target has no target object on which to execute the forwarded action.
What the action runs on
A class action is rooted in an instance of its owning class and uses self for that object. When Act As For Actions forwards a ProductSale row to its Category, self in the Category action is the Category, not the ProductSale.
For example, if ShowCategory is a Category class action, its action logic and enable expression evaluate in Category context. See Documentation:Class actions and Training:What an Action can do for how class-action context, execute expressions, and enable expressions work.
Avoid duplicated action logic
Do not create a copy of every Category action on ProductSale only to navigate to Category and repeat the same behavior. Use Act As For Actions when the ProductSale row should act on its related Category.
If actions genuinely belong on both classes but must share behavior, place the shared logic in a method and let each thin class action call that method. This keeps class ownership clear and avoids duplicated implementation.
Use a ViewModel action instead when the behavior depends on the current ViewModel state, such as vCurrent_ or vSelected_ variables, rather than on one related object.
Limits and checks
- Act As For Actions affects the availability and target of class actions. It does not change which objects the nesting displays.
- It is intended for actions on a single related object per displayed row. Do not use an expression that leaves several possible action targets.
- Review the actions exposed in the view. A related class can have actions that are not meaningful from the displayed object's context; exclude those actions from the view as needed.
- Verify action availability with representative data, including rows where the navigation has no target and rows whose related object has a subclass.
