Custom Java Actions in Mendix
There is no direct way in Mendix where we can call Java code. To include any custom Java code, we can use Java Actions. This article will cover the steps on how to add and make use of a Java Action. We will be using simple Java program for different mathematical calculation operations – for example, Add, Subtract and Multiply.
Create a page to input two integer variables and select mathematical operation to be done.
Let’s create a Java Action to execute our Java code which will be executed through a microflow on click of Calculate Button.
Right click on the module Math Operation, click on add other and select Java Action. Name Java Action as MathOperation
Configure the Java Action
a) Add Parameters under the general tab:
b) Check ‘expose as microflow action’ under Expose as microflow action tab in order use the Java Action in microflow:
You can get more in-depth on Java Action properties information HERE
The Java Action created should be available under the created category in Toolbox bar.
The next step is to execute the Java Action using microflow. Let’s create a microflow:
Add an Action activity to call the Java Action and map the parameters and result.
In order to proceed with further steps, we need to install eclipse to write our custom Java code.
Deploy the solution for Eclipse by clicking on the ‘Deploy for Eclipse’ under project:
Click on Show project directory in explorer:
Import the project in Eclipse…
Go to Java file under mathoperation. Actions:
Locate the placeholder with commented statements (Begin user code and end user code):
You can write your java code here. The modeller will never override your code placed between these two commented statements.
Once done, run the project from modeller and try executing your code from screen:
Need further technical advice or support?
© 2018 Velocity IT Ltd