Keep Java parameters always the same: With ParameterN-suffix - Mendix Forum

Keep Java parameters always the same: With ParameterN-suffix

16

The parameter names in Java a now automatically generated and classes are taken into account when generating the name.

Let's say I have a parameter named: Person. By default in the Java action, this will also be called Person. However, when also an entity named Person is available, the parameter will be named: PersonParameter1. Now, when importing these actions in other projects, this could lead to a change of the parameter name.

My suggestion: Always apply <name>Parameter1 and never change it during import.

asked
4 answers

The reason you are getting these errors is because you are not following Java coding conventions. In Java classes start with an upper case letter and objects and variables start with a lower case letter. Therefore, each input parameter of a Java action should start with a lower case letter (since it's an object or variable, not a class). If you do this, none of this renaming will take place.

Instead of this renaming, which I agree is confusing, Mendix should just throw an error if you try to use an object named Person if you also have a Person class: you're writing Java, you might as well follow best practices if the language is picky about these things. PersonParameter1 just clutters your code even more.

Created

Bart,

Voted for your idea, because we also run frequently into problems when importing modules and Mendix decided to change parameter name "AnyObject" to "AnyObjectParameter1". Maybe because in any of the modules an entity with the name "AnyObject" already exists.

 

When in the USER CODE section a reference to the original parameter name "AnyObject" exists, a compile error occurs after Mendix decided to change AnyObject to AnyObjectParameter1:

    public Java_action(IContext context, IMendixObject AnyObjectParameter1)
    {

...

        // BEGIN USER CODE

                if (this.AnyObject != null) {
                    return true;
                }

        // END USER CODE

 

Could Mendix change AnyObject to AnyObjectParameter1 in the USER CODE section too? Or does Mendix ignore the USER CODE section completely?

 

And yes, when you add an Entity name “AnyObjectParameter1” in any of the modules (who does this?), in that case Mendix still changes AnyObjectParameter1 to AnyObjectParameter2 and you get compilation errors again.

 

 

Created

The really weird thing about it is that it appears to be renaming one parameter but not another.

so in my auto-generated source constructor after importing the module looks like:

    public PublishTopic(IContext context, IMendixObject TopicParameter1, IMendixObject Message)
    {
        super(context);
        this.__TopicParameter1 = TopicParameter1;
        this.__Message = Message;
    }

Created

Sorry to dig up an old thread, but I'm currently seeing odd behaviour when exporting and importing a module between projects that sounds like it's related to this.

I have a parameter on a java action which is called "Message", and the auto-generated method in the java source has named this parameter  "MessageParameter1". After exporting and re-importing this module into another project, I get a compilation error "cannot find symbol", as the auto-generated java code wrapping the action has changed the parameter name in the source to "Message".

I believe I have also seen this behaviour when updating changes from repositories and at other apparently arbitrary times during development. Each time, I need to edit and recompile the java source.

 

 

Created