Use of constants in Java actions

3
Can I access a constant in a Java action directly, or is it necessary to pass it as a parameter from the calling microflow?
asked
3 answers
3

Your second option is better. So, pass the constant as a parameter to your Java action from your microflow. In this way everything is type checked.

answered
1

I would advise against using constants directly in Java actions for two reasons:

 - you're coupling your Java action to the constant, making it harder to reuse
 - the usage will not show up when you search for usages of the constant in the modeller.

So passing them as an argument is better, this makes it explicit that your Java action does something that relies on the value of the constant.

answered
0

A couple of years later, you can access them directly (with the additional benefit of type checks), because they are contained in the generated code, just like actions and entities. You'll need the class Constants in package <module name>.proxies.constants; this is an example of how it looks like:

// This file was generated by Mendix Business Modeler 5.0.
//
// WARNING: Code you write here will be lost the next time you deploy the project.

package interfaces_paymentterminal.proxies.constants;

import com.mendix.core.Core;

public class Constants
{
	// These are the constants for the Interfaces_PaymentTerminal module

	public static Long getInboundPortAdministration()
	{
		return (Long)Core.getConfiguration().getConstantValue("Interfaces_PaymentTerminal.InboundPortAdministration");
	}

 

answered