Mendix uses visual models called microflows to define the logic of your application. A microflow is a visual way of expressing what traditionally would be written in code. This how-to explains how you can create a custom save button on a detail page using a microflow. You will replace a default save button with the save button that shows a message to end-users after they click it.
This how-to will teach you how to do the following:
- Recreate the logic of the default Save button
- Create a custom Save button
Before starting with this how-to, make sure you have completed the following prerequisites:
- Create a basic data layer (for details, see How to Create a Basic Data Layer)
- Create overview and detail pages for the customer object (for details, see How to Create Your First Two Overview & Detail Pages)
- Create a menu item to access the customer overview page (for details, see How to Set Up the Navigation Structure)
3 Replacing the Default Save Button with a Custom One
To replace the default Save button with a custom one, follow these steps:
Open the Customer_Detail page:
Select the Save button press Delete to remove it.
Right-click the drop-zone under the Cancel button, select Add widget, and then select Call microflow button.
In the Select Microflow dialog box, click New to create a new microflow. called Customer_Save.
After the button is created, open its Properties pane.
Change the Caption property to Save:
Set a floppy disk as the Icon:
You have created a button that calls a microflow.
4 Recreating the Default Save Behavior
You need to recreate the default Save behavior to customize it afterwards. Do the following:
Right-click the new Microflow button and select Go to microflow to open the new microflow. The microflow should look like the one below:
Open the Toolbox and select the Commit object(s) activity there:
Drag a Commit object(s) action from the Toolbox to the flow between the start and end events.
Double-click the Commit object(s) activity to open its properties.
In the Input section, select Customer for Object or List, and click OK:
Open the Toolbox, find the Close page activity there, and drag and drop it to the flow after the Commit object(s) activity:
You have recreated the default Save button logic.
5 Extending the Microflow with Your Own Functionality
To extend the logic with a custom message that will be shown when end-users click the button, do the following:
Open Toolbox, find the Show message activity, and drag and drop it after the Close page activity.
Double-click the new activity to open its properties.
In the Template property enter a text that will be displayed in the message. Type in Customer is saved!
Click OK to save the changes.
Congratulations! You have created a microflow and customized the Save button: