How to create a new java class to be used in a java action?

0
Hello I wanted to know how could I create a new class in Java that I need to use in a Java action? Should it be created in the java action itself or somewhere else? Thank you for your help  
asked
4 answers
1

I would put it at the bottom of your Java Action class code. There is space there to add new code that the executeAction method can access. Put it between the “//BEGIN EXTRA CODE” and “//END EXTRA CODE” comments in the Java Action.

Alternatively, you can create a whole new class and save it in your module’s folder in the javasource directory. Have a look at the Community Commons module. This is the approach it takes.

Good luck!

answered
2

Hello Audelia,

 

It's the best practice to create the Java action in Studio Pro and then go to App → Deploy to Eclipse. Then open the project in Eclipse and implement your code. This is the suggested approach. Creating a new class in Java and using that as a utility class in Java action is possible but first creating a Java class and doing reverse engineering is not suggested.

 

Hope this answers your question.

answered
0

Create a new java action in Studio Pro and it will write the framework of the java class for you. You just need to fill in the implementation details

answered
0

Hi Audelia! If I understand your question correctly, you already have a Java action generated and used by Mendix and want to create your own class to use in this Java action.

 

While I haven't found a best practice defined by Mendix, a common method I see used is to create the extra files in the project/javasource/moduleNameOfJavaAction directory. Just don't forget to export these files as resources with your module export.

 

Hope this helps!

answered