🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
VCurrent Root
This page was created by Stephanie on 2024-06-04. Last edited by Wikiadmin on 2026-07-29.

vCurrent_Root lets you refer to the current object at the root level of a cursored ViewModel when you write OCL or an action.

What vCurrent_Root means

vCurrent_Root is the root-level form of the built-in vCurrent_<ViewModelClassName> variables. MDriven creates vCurrent_ variables for ViewModel nestings; the suffix identifies the nesting to which the variable belongs.

The variable holds the object that is currently active, focused, or last clicked in that root-level ViewModel nesting. Its type matches the type of that nesting.

For example, if the root ViewModel nesting is named Root and represents Thing objects, use vCurrent_Root where you need the currently active Thing:

vCurrent_Root.SomeString

Do not treat Root as a model class name. It is the generic root-level nesting name used in the variable name.

When to use it

Use vCurrent_Root when the expression must act on the object currently active at the root level, especially in a ViewModel action that is intended to act on the user's current row or object.

For a ViewModel rooted on one object, the root-level current object does not change. In that case, vCurrent_Root points to that one object and is equivalent to self when the expression is placed on the root ViewModel class.

Need Use Example
Act on the currently active object in the root nesting vCurrent_Root vCurrent_Root.SomeString
Refer to the object being rendered at the expression's current ViewModel location self In a detail nesting, self is that detail object.
Refer to the object supplied when a rooted ViewModel was opened selfVM.RootObject selfVM.RootObject->safeCast(Thing).SomeString

vCurrent_Root, self, and RootObject

These expressions can identify the same object in a small rooted ViewModel, but they have different meanings. Choose the one that expresses your intent.

  • vCurrent_Root is the current object for the root-level nesting. It is a vCurrent variable and therefore represents ViewModel cursor state.
  • self depends on where the expression is written. In a root ViewModel class it refers to the root object being rendered; in a nested detail class it refers to the detail object being rendered.
  • selfVM.RootObject is the specific object instance used to open the ViewModel. The reference is read-only while the view is open. Because its type is not known statically, cast it before accessing members of the model object.

For the full rules and rendering implications of vCurrent and self, see Documentation:How to use vCurrent and “self” correctly in viewmodels. For RootObject syntax and casting, see Documentation:OCLOperators RootObject.

Use it in an action

To make an action operate on the current root-level object:

  1. Add the action where it is available from the root-level ViewModel.
  2. In the action's OCL or EAL expression, refer to vCurrent_Root when the action targets the root-level current object.
  3. Open the action editor and inspect the available variables if you are unsure of the nesting name or variable type.
  4. Test the action after changing the current object to confirm that it acts on the intended object.

For actions defined on model classes, see Documentation:Class actions. For ViewModel action behavior and configuration, see Documentation:ViewModel actions.

Related cursor variables

vCurrent_Root represents one current object. If the root-level list allows multiple selection, MDriven also maintains the corresponding vSelected_ collection. Use that collection when an action must process every selected object rather than only the current one.

The client can automatically select the first row in a WebUI DataGrid when the list does not use multi-select. Multi-select has different default selection behavior, and Nesting.AutoSelectFirstRow can explicitly control it. See Documentation:VCurrent and vSelected for selection behavior and configuration.

Rooted and unrooted ViewModels

A vCurrent_Root variable is about the root-level ViewModel nesting; it is not the same concept as whether a ViewModel requires an object when it opens.

If your ViewModel is intended to open on a supplied root object, mark that intention with the Requires root setting. If it is a browser or seeker that starts without a supplied object, do not supply a root object. This prevents warnings caused by a mismatch between the ViewModel configuration and the action that opens it. See Documentation:Explaining “The ViewModel does not require a root object” warning.

See also