🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Bootcamp:Chapter 12
This page was created by Hans.karlsen on 2022-12-18. Last edited by Wikiadmin on 2026-07-29.

You will replace generated BrandOfCar AutoForms with maintained views, add brand images throughout the car application, and restrict brand and registration-number changes to administrators.

This chapter continues from Chapter 11. Complete it in the same model before continuing to Chapter 13.

What you will build

By the end of this chapter:

  • Each BrandOfCar can store a BrandImage of Blob type configured as an image.
  • The image appears in the brand-management view, car view, ownership-transfer document, and car seeker.
  • The generated BrandOfCar AutoForms are replaced by explicit ViewModels.
  • Only an administrator can change a car's brand or registration number.

The chapter uses a ViewModel to define what users see and edit. It also uses OCL expressions to control whether controls are read-only or visible.

Before you begin

  1. Open the model completed in Chapter 11.
  2. Save the model before making changes. You will later remove generated AutoForms, which also removes dependent actions and ViewModels.
  3. Start the application when instructed and reload the web application after model changes.

Replace the brand AutoForm with ManageBrand

The generated AutoForm is useful while exploring a model. In this exercise, you adopt it so that it becomes a ViewModel you maintain yourself.

  1. Adopt the AutoForm AutoFormBrandOfCar and rename it to ManageBrand.
  2. Rename the class action that opens the form so that it also has the name ManageBrand. Errors are expected because existing expressions can still refer to the old generated name.
  3. Remove the Cars widget.
  4. Delete the actions MultilinkCars and DeleteThis. They now have errors because they use vCurrent_<oldname>.
  5. Delete every remaining widget except the Name widget.
  6. Review how actions are included or excluded by the opt-in/opt-out behavior. Confirm which actions remain available after you remove the generated widgets.

Add the BrandImage attribute and widget

  1. Add a generic column to ManageBrand named BrandImage.
  2. In the column's Expression box, enter:
self.BrandImage
  1. In the lower part of the debugger, select the blue highlighted text Add new Attribute BrandImage.
  2. In the dialog, select Type, choose Blob, and select OK. Close the debugger dialog with OK.
  3. Resize the BrandImage widget.
  4. Remove the presentation text from the BrandImage column:
    1. Delete <Name> from the Presentation box.
    2. Resize the widget again after the presentation has been removed.
  5. Return to the model and select BrandImage:Blob? on BrandOfCar.
  6. In the details pane, select the value box next to BlobType and choose Image.

A Blob is a binary attribute. Setting its BlobType to Image makes the widget handle the value as an image rather than as unspecified binary data.

Test brand image editing

  1. Start the application.
  2. Open Auto Form Brand Of Car Seeker, select the first car, and navigate to ManageBrand.
  3. Select the image widget and upload an image for the brand.
  4. Repeat for the car brands you want to test.

The ManageBrand view should show an image widget and retain the uploaded image for each brand.

Create a maintained BrandSeeker

  1. Create a new ViewModel that seeks BrandOfCar. Name it BrandSeeker.
  2. Use UIFirst to copy the SeekerAutoForm logic.
  3. Delete the column AsString : self,asString.
  4. Select ManageBrand as the navigation action from the seeker.
  5. In the BrandSeeker ViewModel, delete these columns:
    • ChangeTime : self.ChangeTime
    • CreateTime : self.CreateTime
    • Guid : self.Guid

Set global-action menu order

  1. Select the global action BrandSeeker.
  2. In the Global Actions dialog, find Sort order in Group under How the menu looks and where it is placed and enter x.
  3. In the same area, open Menu Group by selecting the box with dots.
  4. In the EditMenuGroups dialog, enter z in the row for IControltheMenuGrouping/AtAllLevels.
  5. Select OK and verify that the menu order changes.

The sort-order and menu-group values determine where an action appears in the application menu. Use this test to observe how action ordering is handled within a menu group.

Drop generated AutoForms

After the maintained views are in place, remove the generated AutoForms from the model.

  1. Right-click the BrandOfCar class.
  2. Select AutoForms, then Drop AutoForms.
  3. Save the model.
  4. Reload the web application.

Important: Dropping AutoForms removes related generated actions and ViewModels. This is expected. Check the application after reload and repair navigation that still points to a dropped AutoForm.

When a user has only one available navigation action, the application uses that action on the first click. Verify this behavior after the AutoForms are removed.

Show the brand image where cars are used

Use the UsedBy list to identify views that consume BrandOfCar.

  1. Right-click BrandOfCar and inspect the UsedBy list.
  2. Open ProperCarView.
  3. Add the BrandImage column.
  4. Delete <Name> from the column's Presentation box.
  5. Place and resize the BrandImage widget next to the Registration Number widget.
  6. Open CarTransferOwnershipDocument. Add a column that displays the brand image.

When adding the document column, practice all three ways of locating the correct expression:

  • Select Add Column.
  • Select Add column from model.
  • Enter the expression manually.

The expression depends on the current ViewModel context. Use the model picker and the association path available in that context to reach the car's BrandOfCar and its BrandImage.

Update CarSeeker and repair NewCar

  1. Open the CarSeeker ViewModel.
  2. Rename the AsString column to Presentation.
  3. Add the BrandImage column.
  4. Save the model.
  5. Find the NewCar action. It no longer has a view because it pointed to a dropped AutoForm.
  6. Change NewCar so that it opens ProperCarView.

Test that the car seeker displays the presentation and image, and that NewCar opens ProperCarView.

Add an administrator-only brand selector

The existing brand selector in ProperCarView can allow any user to set a car's BrandOfCar. Add a separate setter control for administrators and then apply the read-only rule to the view.

  1. In ProperCarView, add a nested ViewModel class.
  2. Select Singlelinks with setter, then select BrandOfCar : BrandOfCar.
  3. Drag the new button above Car Owner.
  4. Rename BrandOfCar2 to BrandOfCarForAdmin.

Restrict brand editing

  1. Select the dotted box next to the ReadOnly Expression for the BrandOfCarForAdmin control.
  2. Enter this OCL expression:
not SysSingleton.oclSingleton.CurrentUser.IsAdmin
  1. Save the model.
  2. Run the application and test with the two users created earlier: user a as administrator and user b as a non-administrator.

The expression evaluates to true for a user who is not an administrator. A true ReadOnly expression prevents that user from editing the control.

  1. For BrandOfCarForAdmin, enable FollowEnable beside VisibleExpression. A check mark appears.
  2. Test that the administrator-only control is not visible to a non-administrator.

Restrict registration-number changes

The registration number must also be protected. Apply the administrator access group to creating cars, then move the read-only rule to the ProperCarView root so that it covers the view's editable content.

  1. Set the Access Group IsAdministrator on the NewCar action.
  2. Cut the following expression from the BrandOfCarForAdmin combobox ReadOnly Expression:
not SysSingleton.oclSingleton.CurrentUser.IsAdmin
  1. Clear the check mark on the BrandOfCarForAdmin VisibleExpression FollowEnable setting.
  2. Select the root of the ProperCarView ViewModel.
  3. Paste the expression into its ReadOnly Expression.
  4. Save the model and test the application again with users a and b.
User Expected result
Administrator (a) Can open NewCar and edit ProperCarView, including the brand and registration number.
Non-administrator (b) Cannot use NewCar because it requires IsAdministrator. When viewing ProperCarView, the read-only expression prevents edits, including changes to the brand and registration number.

Verify the completed chapter

  1. Confirm that a BrandOfCar has a Blob attribute named BrandImage with BlobType Image.
  2. Confirm that ManageBrand can display and edit the image.
  3. Confirm that BrandImage appears in ProperCarView, CarTransferOwnershipDocument, and CarSeeker.
  4. Confirm that BrandSeeker is available in the intended menu position.
  5. Confirm that no required action still points to a dropped AutoForm.
  6. Confirm that the non-administrator cannot create a car or modify the brand or registration number in ProperCarView.

The completed exercise model is available as File:ModelAfterChapter12.zip.

See also