JAVA Action in Mendix

Mendix Java application development requires modelling microflows which in turn form the business and backend logic. Microflows are very powerful but in a way are also limited to the widgets and components already available in Mendix Toolbox. If we are stuck in a situation to build a complex backend logic and the in-built components are no longer helpful, Mendix provides a way to extend the functionality by writing code in Java and exposing this through a custom Java Action which can then be used within a microflow to perform the complicated task.

Mendix Project can be exported as an Eclipse General Project and then we can start writing our Java Action in Eclipse IDE. The Java Action which we create can accept Parameters as Input and can return an Object (which inherits iMendixObject in Java). This returned Object can be processed further in Microflow.

Adding a new JAVA Action in Mendix:

  • Right-click the Module and select Add other > Resources > Java action.
  • Enter a name (GetRandomAlphaNumericString) for the Java action.
  • In the Java Action call Wizard enter input Parameter as an Integer as per below screenshot and click OK.
  • Enter the Return Type as String in the Wizard dialog box and save the Java action.
  • Click Project –> Deploy for eclipse to create a general eclipse project which can be imported in Eclipse.
Adding a new JAVA Action in Mendix
Mendix creates a Java class to create a Eclipse project in Mendix

Java Action in Eclipse

For every Java Action, Mendix creates a Java class where there are hooks (Insertion points to add custom logic) which can be edited to perform any action which is not directly possible using Microflows.

Invoking the Java Action in a Microflow

In the Mendix microflow, you call the Java Action using the Java Action Call widget. Any call to the microflow will invoke the Java action and returns the result.

call the Java Action using the Java Action Call widget in Mendix microflows

Mendix offers Java Action as an extensible way to build custom actions in the form of Java Code without which we are only limited to using the widgets and apps already present in Mendix or by 3rd Party Developers in App Store. We can also import 3rd Party Open Source Java Libraries and add it to our Classpath of the Eclipse Mendix Project and start using the API’s provided in those Libraries.