Calling userActionCall from Java in Mendix 8.7 means passing the context twice - is this right?

0
Mendix 8.7 gave us a new way to call a Java Action from another Java Action – com.mendix.core.Core.userActionCall. This gives us a fluent interface for passing parameters and executing the call. However, it appears we have to pass the Context twice. Once as the first parameter in withParams, and once in execute. I’m sure there is a really good reason for this behaviour, but I can’t see it.  For example, if I create a simple Java Action to add two longs together and return them, I get the following Java.   // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package testcallingjava.actions; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.webui.CustomJavaAction; public class JA_Add extends CustomJavaAction<java.lang.Long> { private java.lang.Long First; private java.lang.Long Second; public JA_Add(IContext context, java.lang.Long First, java.lang.Long Second) { super(context); this.First = First; this.Second = Second; } @java.lang.Override public java.lang.Long executeAction() throws Exception { // BEGIN USER CODE return this.First + this.Second; // END USER CODE } /** * Returns a string representation of this action */ @java.lang.Override public java.lang.String toString() { return "JA_Add"; } // BEGIN EXTRA CODE // END EXTRA CODE }   To call this Java Action using the new userActionCall functionality, I need to pass 3 parameters – the Context, and two Longs. I also need to execute with the Context.   java.lang.Long result = com.mendix.core.Core.userActionCall("TestCallingJava.JA_Add") .withParams(this.getContext(), 2, 3) .execute(this.getContext()); It feels like the Context should only need to be passed once as I can’t see how it would ever be different. Is this right, or have I misunderstood how this works?
asked
1 answers
1

I can imagine a more complex action that uses the context for the java code and execute the java action in a systemcontext, by creating a system context in the calling java action (with Core.createSystemContext();)

I would imagine this to be an exceptional case, but one that can be implemented with the current construction.

answered