TypeParameter for Enums in Java Actions - Mendix Forum

TypeParameter for Enums in Java Actions


Currently it's possible to select a TypeParameter for an object in Java_Actions, so that the action can be reused for multiple entities, without reverting to fault-prone and hard to maintain methods such as strings that map to an entity in your domain model. This is great. However I would also like similar functionality for Enumerations.

I want to make a Java action that loops over an enumeration, and calls a microflow for each enum-value. In this microflow I can then use the enum value to check if an object already exists, and create it if not. Currently I would have to make this Java action for each enum, thus each entity in my domain model where I want to use this.

2 answers

Hi Rom,

Thanks for the workaround. We've actually implemented it that way, and that was the reason for my feature request: I'm not a fan of solutions that have a high risk of breaking at runtime with no hint of the problem whatsoever in the modeler.


A workaround for this feature request:

Create a Java action (IterateEnum) with the following input parameters:

String enumerationName (expected input: modulename.proxies.EnumerationName - lowercase.lowercase.CaseAsUsedInModeler)

String microflowName

	HashMap<String, Object> params = new HashMap<>();
	int i = 0;
	Class enumClass = Class.forName(enumToIterate);
	if (enumClass.isEnum()) {
		for (Object o : enumClass.getEnumConstants()) {
			params.put("Enum", o.toString());
			params.put("SortIndex", i);
			Core.execute(this.getContext(), microflow, params);
	return true;

This Java action calls a microflow with input parameters Enum and SortIndex (which explains the i variable in the code snippet).