You can use AutoForms in MDriven Designer to generate working, model-based forms and seekers for every class, making them useful for early prototyping, test-data entry, and exploring a new or existing model.
What AutoForms generate
An AutoForm is a generated ViewModel representation of a class in your model. MDriven analyzes the class definition and produces standard views from its attributes and associations.
When you refresh a model with AutoForms enabled, MDriven provides a seeker for each class. A seeker is a view where you can search for instances of that class, create an instance, and open its form.
For example, if your model contains these classes:
InvoicewithCustomerandNumberattributesInvoiceRowwithAmountandDescriptionattributesProductwithNameandPriceattributes
AutoForms create seekers and forms that let you create invoices, add invoice rows, create products, and connect rows to products without first designing custom ViewModels or actions.
Use AutoForms to work with your model
Use AutoForms when you need to inspect the data structure your model describes or enter representative data while you are still shaping the model.
- Start your model in the system prototyper.
- Refresh or reload the model with AutoForms included.
- Open the seeker for the class you want to work with, such as
Invoice. - Search for an existing object, or choose the create option when no object exists.
- Save the new object.
- Open the object and choose to show its form.
- Enter attribute values and use associations to navigate to related objects.
In the invoice example, the Invoice form shows its attributes, such as customer and invoice number. Its InvoiceRows association is a multi-link, so you can open the related rows, create rows, and edit each row. From an InvoiceRow, you can use a single link such as Product to search for a product or create one when the seeker has no matching product.
What you can do in an AutoForm
| Model element | AutoForm behavior | Example |
|---|---|---|
| Attribute | Display and edit the value using a control selected from the value type. | A string description is shown as a text entry control; a Boolean value is shown as a check box. |
| Single link | Search for and set one related object. You can create a related object from the seeker when needed. | Set InvoiceRow.Product by searching for a product, or create Good burger and then select it.
|
| Multi-link | Open and manage the collection of related objects. | Open Invoice.InvoiceRows, add rows, and edit their amount and description.
|
| Class | Create, search for, open, and delete instances through its generated seeker and form. | Create an Invoice from the Invoice seeker, save it, then open its form. |
AutoForms therefore give you a usable route through the model even before you have created custom ViewModels and actions.
Refreshing regenerates AutoForms
AutoForms are generated from the current model. Refreshing the model with AutoForms recreates generated forms so that they follow changes to classes, attributes, and associations.
Important: manual changes made directly to an AutoForm are discarded when AutoForms are recreated. Do not use an unadopted AutoForm as the long-term home for UI work.
This makes AutoForms safe to use for experimentation: regenerate them as the model changes, then preserve the views that you decide to develop further.
Adopt an AutoForm before customizing it
An adopted AutoForm becomes your own ViewModel. AutoForm regeneration does not replace adopted forms.
Use this workflow:
- Generate AutoForms and use them to validate the model and enter test data.
- Identify a generated form that is a good starting point for a real user workflow.
- Adopt that AutoForm before making manual changes.
- Customize the adopted ViewModel: change columns, layout, labels, and actions as needed.
- Continue to regenerate the remaining AutoForms as the model evolves.
For example, you may retain AutoForms for Product and InvoiceRow during development, while adopting the Invoice form to create an invoice-specific screen that shows customer, number, invoice rows, and product names in the arrangement your users need.
Move from an AutoForm to a designed ViewModel
An AutoForm and a manually designed ViewModel use the same ViewModel concepts. When you create a ViewModel yourself, you select the root class and decide whether the view requires a root object.
A root object is the object available as self in root-level OCL expressions. For an Invoice ViewModel that requires an invoice object, self refers to the Invoice being displayed.
You can then add columns based on OCL expressions. MDriven selects a UI widget from the expression result type. For example:
| OCL expression result | Typical rendered control | Example use |
|---|---|---|
| String | Text box | Show or edit an invoice-row description. |
| Boolean | Check box | Show or edit a true/false value. |
| Byte array containing image data | Image control | Display stored image data. |
Use the ViewModel preview to arrange controls in the grid and set how many rows or columns a control spans. The preview warns when controls collide. An expression must be valid and return a result; otherwise MDriven cannot determine what to render.
To open a designed ViewModel from an object, create a class action for the relevant class. For example, associate a Show action with Invoice so that the action is available when an Invoice is shown from its AutoForm seeker.
When to use AutoForms
| Situation | Recommended approach |
|---|---|
| You have a new model and need to create data immediately. | Generate AutoForms and use the generated seekers and forms. |
| You are validating associations and navigation. | Use AutoForms to create related objects and follow single links and multi-links. |
| You are exploring a reverse-engineered database model. | Use AutoForms alongside DB Reverse to inspect and work with the imported model. |
| A view has become part of the application workflow. | Adopt the AutoForm, then customize its ViewModel and add appropriate actions. |
| You need a focused, task-specific user experience. | Create or customize a ViewModel rather than relying on the generated layout. |
Use AutoForms during rapid iteration
AutoForms support an iterative workflow: model the information, generate forms, enter and inspect data, gather feedback, and then adopt and refine the views that users need. For local prototype iteration, see Faster prototyping with Turnkey.
For a walkthrough of generating seekers, creating related objects, and combining AutoForms with a designed Invoice ViewModel, watch AutoForms Faster Better Cooler.
