ViewModel variables
No edit summary
No edit summary
Line 1: Line 1:
All ViewModels have predefined variables that help you interact with the ViewModels and its data. Depending on what you're using your View model for, you use different variables and different variables are available. 
All ViewModels have predefined variables that help you interact with the ViewModels and their data. Depending on what you're using your ViewModel for, you use different variables and different variables are available. 


The most commonly used are V current and V selected and V self-VM.  V current and V selected are used when you're having a cursored view model. (Please read more about cursored and uncursored view models in a separate article.) You can turn off the V current and V selected variables by setting a tagged value that you can read about ()here
The most commonly used are vCurrent and vSelected and selfVM. vCurrent and vSelected are used when you have a cursored ViewModel. (Please read more about [[Cursored or Full Tree|cursored and uncursored viewmodels]] in a separate article.) You can turn off the vCurrent and vSelected variables by setting a tagged value that you can read about (here). 


The use for V current and V selected is that you can at runtime see which item in a list that has been clicked upon by the user. Or in the case of if it is turned on that they can select multiple items in a list, then those objects that has been selected will be available in the collection called V selected  underscore and the name of the view model clause.  In this example we will have one V current that is not going to change because this is  a rooted view model and V current view one thing points to one thing object.  It will be the same as self. 
The use for vCurrent and vSelected is that you can see at runtime which item in a list has been clicked upon by the user. Or in the case of if it is turned on, they can select multiple items in a list, then those objects that have been selected will be available in the collection called <code>vSelected_</code> and the name of the ViewModel class.  In this example, we will have one vCurrent that is not going to change because this is a rooted ViewModel and <code>vCurrent_ViewOneThing</code> points to one thing object - it will be the same as self. 


Remember that the V current points to the view model class object that is active regardless  of in which view model you are referencing that variable.  In contrast, "self" is dependent on where the expression is placed.  If it is an expression in for example the blue detail view model clause in this example
Remember that the vCurrent points to the ViewModel class object that is active regardless of which ViewModel you are referencing that variable. In contrast, "self" is dependent on where the expression is placed. If it is an expression in, for example, the blue detail ViewModel class in this example:


()
[[File:ViewModel - image 6.png|frameless|link=https://wiki.mdriven.net/index.php/File:ViewModel_-_image_6.png]]


it will be a detail object. Because this is an expression here the action column on the root green view model class  self references the root of the whole view.   
it will be a ''detail'' object. Because this is an expression here, the action column on the root green ViewModel class "self" references the root of the whole view.   


()
[[File:ViewModel - image 2.png|frameless|link=https://wiki.mdriven.net/index.php/File:ViewModel_-_image_2.png|264x264px]]


If I make view model actions, they very often use V current or V selected.  Of the list of things or the specific object that action should act upon. 
If I make view model actions, they very often use V current or V selected of the list of things or the specific object that action should act upon. 


You also have self VM. Self VM references the running view model itself and it is used within action language expressions to execute things or to find out the state of the view itself, for example, to execute an action, to execute something in persistent storage that is SQL,  to execute the query plan again to find out which objects have been changed in the view, and to examine or execute things related to access groups or security. 
You also have selfVM. selfVM references the running ViewModel itself and is used within action language expressions to execute things or find out the state of the view itself, for example, to execute an action, to execute something in persistent storage that is SQL, to execute the query plan again to find out which objects have been changed in the view and to examine or execute things related to [[access groups]] or [[security]]


You can also define your own variables for any use that you want for example to keep a reference to an object that the user is working on. Also note that if you don't use placing hints that is you don't have a user interface that you use this view model for an API or a report, the available variables changes. For example variables that are not for V current and V selected is not used in reporting.  Moreover in an API scenario V current and V selected are sometimes used in special circumstances  to process their JSON or XML being imported but most of the times they are not used. 
You can also define your own variables for any use that you want, for example, to keep a reference to an object that the user is working on. Also note that if you don't use placing hints, that is, you don't have a user interface that you use this view model for an API or a report, the available variables changes. For example, variables that are not for vCurrent and vSelected are not used in reporting. Moreover, in an API scenario vCurrent and vSelected are sometimes used in special circumstances to process the JSON or XML being imported but most of the time, they are not used. 


There are also variables defined in specific action cases - for example, if you have a  model dialog that is an action that opens another view and then to access its result, you get specially named variables that are available in the action that executes after the model has been closed.   
There are also variables defined in specific action cases - for example, if you have a  model dialog that is an action that opens another view and then to access its result, you get specially named variables that are available in the action that executes after the model has been closed.   


You can always see which variables are available by for example opening the OCL editor for attribute or as in this example, the action editor for an in-view action and then exploring in the action editor which methods and variables are available on the right-hand side as in this example.
You can always see which variables are available by, for example. opening the OCL editor for attribute or as in this example, the Action editor for an in-view action and then exploring in the Action editor which methods and variables are available on the right-hand side as in this example.
 
(image)

Revision as of 07:18, 10 August 2023

All ViewModels have predefined variables that help you interact with the ViewModels and their data. Depending on what you're using your ViewModel for, you use different variables and different variables are available. 

The most commonly used are vCurrent and vSelected and selfVM. vCurrent and vSelected are used when you have a cursored ViewModel. (Please read more about cursored and uncursored viewmodels in a separate article.) You can turn off the vCurrent and vSelected variables by setting a tagged value that you can read about (here). 

The use for vCurrent and vSelected is that you can see at runtime which item in a list has been clicked upon by the user. Or in the case of if it is turned on, they can select multiple items in a list, then those objects that have been selected will be available in the collection called vSelected_ and the name of the ViewModel class.  In this example, we will have one vCurrent that is not going to change because this is a rooted ViewModel and vCurrent_ViewOneThing points to one thing object - it will be the same as self. 

Remember that the vCurrent points to the ViewModel class object that is active regardless of which ViewModel you are referencing that variable. In contrast, "self" is dependent on where the expression is placed. If it is an expression in, for example, the blue detail ViewModel class in this example:

ViewModel - image 6.png

it will be a detail object. Because this is an expression here, the action column on the root green ViewModel class "self" references the root of the whole view. 

ViewModel - image 2.png

If I make view model actions, they very often use V current or V selected of the list of things or the specific object that action should act upon. 

You also have selfVM. selfVM references the running ViewModel itself and is used within action language expressions to execute things or find out the state of the view itself, for example, to execute an action, to execute something in persistent storage that is SQL, to execute the query plan again to find out which objects have been changed in the view and to examine or execute things related to access groups or security

You can also define your own variables for any use that you want, for example, to keep a reference to an object that the user is working on. Also note that if you don't use placing hints, that is, you don't have a user interface that you use this view model for an API or a report, the available variables changes. For example, variables that are not for vCurrent and vSelected are not used in reporting. Moreover, in an API scenario vCurrent and vSelected are sometimes used in special circumstances to process the JSON or XML being imported but most of the time, they are not used. 

There are also variables defined in specific action cases - for example, if you have a  model dialog that is an action that opens another view and then to access its result, you get specially named variables that are available in the action that executes after the model has been closed. 

You can always see which variables are available by, for example. opening the OCL editor for attribute or as in this example, the Action editor for an in-view action and then exploring in the Action editor which methods and variables are available on the right-hand side as in this example.

(image)

This page was edited 55 days ago on 03/20/2024. What links here