You can create, place, and test actions that open views or act on selected objects in MDriven Designer; this chapter is for Bootcamp learners who completed Training:Bootcamp:Chapter 4.
This chapter uses the PersonSeeker ViewModel created earlier. You will learn how actions determine what users see in the global menu, in a type-specific context, and inside one ViewModel.
Before you begin
- Complete Training:Bootcamp:Chapter 4 and open the model that contains the PersonSeeker ViewModel.
- Save frequently with
Ctrl+S. - Test each completed change in the running web application. In MDriven Designer, save the model before checking the browser.
- If you lose your place, reopen the relevant ViewModel in the ViewModel Editor and expand its yellow Actions node.
Understand the three action types
An action defines something a user can invoke. The action editor is similar for all action types, but the action's scope determines where it is available.
| Action type | Scope | Where the user sees it | Example in this chapter |
|---|---|---|---|
| GlobalAction | The application | The top-level global menu, optionally in a menu group | PersonSeeker opens the PersonSeeker ViewModel |
| Class action | Every object of one class | Where the ViewModel has matching type information | ShowPerson is available for a Person |
| ViewModelAction (also called a ContextAction) | One ViewModel and its selected level | The action area or a control in that ViewModel | DeleteThis deletes the selected Person |
A ViewModel is the definition of a screen and its data context. An action can bring up a ViewModel, execute behavior in the current context, or be invoked by a button placed in a ViewModel.
Work with GlobalActions
A GlobalAction belongs to the application rather than to a model class. It appears in the global menu unless its menu-group settings place it below a menu item.
Open and rename the PersonSeeker action
- In the ViewModel Editor, open PersonSeeker.
- Expand the yellow Actions node.
- Select the blue
/PersonSeekerlink to open its action definition. - Change ActionName from
PersonSeekertoPersonSeekerIAmInControl. - Observe the generated menu preview above ActionName. It updates when the action name changes.
The list on the left of the action editor contains the GlobalActions currently defined in the model. Select AutoFormCarSeeker to inspect another GlobalAction, then select your renamed PersonSeeker action again.
You can also open the same GlobalAction editor from the model diagram by selecting the cog-wheels tool button.
The MenuGroup property determines where a GlobalAction appears in the rendered global menu.
- Select
AutoFormCarSeekerin the GlobalAction list. - Confirm that its MenuGroup is
AutoForms. It does not appear as a top-level action in the rendered main menu. - Clear the MenuGroup value.
- Confirm that the action now appears beside the PersonSeeker action in the top-level menu.
- Restore
AutoForms, either withCtrl+Zor by entering the value again.
A GlobalAction appears in only one menu location. Assigning a menu group removes it from the top level and places it under that group.
A menu-group name can contain levels separated by /.
- Select
PersonSeekerIAmInControl. - Select the three-dot button (
...) beside MenuGroup to open EditMenuGroup. - Select Add menu group.
- Enter
IControlTheMenuGrouping/AtAllLevels, then close the dialog. - Set the action's MenuGroup to
IControlTheMenuGrouping/AtAllLevels. - Inspect the rendered menu. Open IControlTheMenuGrouping, then AtAllLevels. The PersonSeeker action is inside this nested group.
Choose the ViewModel that opens
Under What the action does, Bring Up View Model identifies the ViewModel opened when the user invokes the GlobalAction.
- For
PersonSeekerIAmInControl, verify that Bring Up View Model is PersonSeeker. - Select the three-dot button beside the property. The ViewModel Editor receives focus and shows the selected ViewModel.
- Return to the action editor.
- Temporarily set Bring Up View Model to
Indexand use the three-dot button to verify that the editor now opens Index. - Undo the test change so that the action again opens PersonSeeker.
In the rendered menu, use the ViewModel icon beside an action to open its ViewModel definition in MDriven Designer. Select the action text itself to select that GlobalAction in the action editor.
- Select Add Global Action.
- Set ActionName to
PersonSeekerAgain. - Set Bring Up View Model to
PersonSeeker. - Set MenuGroup to
IControlTheMenuGrouping/AtAllLevels. - Save and inspect the group in the running web application.
Use DividerGroupWithinMenu to create visual sections within the same menu group.
- Set
PersonSeekerAgainDividerGroupWithinMenu toSomeName. Save and inspect the web application. - Set
PersonSeekerIAmInControlDividerGroupWithinMenu to the same value. Save and inspect the result. - Set Sort order in the group to
AAAon one action andBBBon the other. - Save and verify their order in the web application.
- Swap
AAAandBBB, save, and verify that the order changes.
Work with Class actions
A Class action belongs to a class. It is available for objects of that class where the ViewModel has matching type information. For example, an action for Person is available at a Person level, while an action for Car is available at a Car level.
Identify and rename a Person action
- Return to the PersonSeeker ViewModel and expand Actions.
- In Person-Nesting, find either of the two
ShowPersonaction links and open it. - Inspect the action editor. The list contains Class actions for the
Personclass. - There are two
ShowPersonactions. One was copied when you adopted the ViewModel in the earlier chapter. - Rename the action that does not bring up an autoform to
ShowPersonIAmInControl.
Back in the ViewModel Editor, a Class action is identified by the class name in parentheses, for example ShowPersonIAmInControl (Person). Both actions belong to the Person class.
See how type context controls availability
- Change the class of the nesting from
PersontoCar. - Ignore the temporary errors caused by this test.
- Observe that the Person actions disappear and a Car action, such as
ShowCar, becomes available. - Change the nesting class back to
Personand save. - Test both Person actions in the web application. They open different forms, and each form exposes the corresponding Class action that can take you to the other form.
This behavior is type-based: MDriven Designer shows Class actions when the current ViewModel level has the matching class context.
Opt a Class action in or out for a ViewModel level
Type matching usually gives the intended action placement. When you need to control whether a matching Class action is shown at a particular ViewModel location, use the action's opt-in settings.
- Open each Person Class action.
- At the top of its action definition, inspect the list of ViewModel locations whose type information matches the action's class.
- Ensure that the applicable levels are checked for both Person actions.
- Save and verify the result in the web application.
You can also control this from the ViewModel tree:
- In the ViewModel Editor, select the arrow in front of a Class action to opt it out at that location.
- Confirm the change in the web application.
- Use the ViewModel tree again to opt the action back in.
Work with ViewModelActions
A ViewModelAction, also called a ContextAction, belongs to a particular ViewModel rather than to a class. It can be placed at a selected level of that ViewModel tree.
Edit the delete confirmation
- Open the
PersonViewModel. - Expand Actions.
- Open the
DeleteThisaction. - In the action editor, locate AreYouSure.
- Set it to
Wow - wanna delete this person?. - Save and test the action in the web application.
- When the confirmation appears, select Cancel so that you do not delete the Person while testing the prompt.
The left side of the ViewModelAction editor follows the ViewModel tree. It can also show matched Class actions. A true ViewModelAction has no class name in parentheses; a Class action does.
Limit the action to the intended ViewModel level
A ViewModelAction is not constrained by a class, so it can theoretically be available at multiple levels in its ViewModel. Use the level setting in the action editor to keep it where it makes sense.
- In the
DeleteThisaction editor, find the level setting at the upper right. It is initially set toPerson. - Change it to
Car, save, and test the web application. - Confirm that
DeleteThisis now available only when a Car is selected. - Change the setting back to
Personand save. Deleting a Person from the Person level is the intended behavior for this example.
Place a button that invokes an action
A ViewModel button is a control placed in the ViewModel layout. It does nothing until you give it an action-language expression or connect it to an available action.
- Open the
PersonViewModel in the ViewModel Editor. - Add a button.
- Name its column
DeleteMe. - Save and inspect the web application. The button is visible but has no behavior yet.
- Find the button's Is action setting.
- Use the picker beside Is action to select
DeleteThisfrom the actions available in this ViewModel. - Save and test the button in the web application.
The DeleteMe button now invokes the existing DeleteThis ViewModelAction, including its confirmation text. This lets you place a familiar action where users need it without creating duplicate delete behavior.
Check your work
Before continuing, confirm that you can:
- Open PersonSeeker from a GlobalAction in a nested menu group.
- Use MenuGroup, DividerGroupWithinMenu, and Sort order in the group to control global-menu placement and order.
- Recognize a Class action by its class name in parentheses and see it change with the nesting's type context.
- Opt a Class action in or out at a ViewModel location.
- Change a ViewModelAction confirmation message and restrict it to the correct ViewModel level.
- Invoke
DeleteThisthrough the placedDeleteMebutton.
Next chapter
Continue with Training:Bootcamp:Chapter 6.
