在决定用Java解决问题前,其实很多功能在内建的Microflows中都能够解决了,再加上Java有可能会使原本的结构变得更混乱,甚至让之後接手工作的工程师工作上困难,因此,跟自创widget一样,官方不太建议自己用Java写Mendix上的Microflows。
当然,特殊情况下,该写的Java还是要卷起袖子来写,这时要注意, 用Java写出来的activity要符合
1.单一职责原则
2.符合Unix哲学
3.让不同的microflows都能够重复使用
点选Project explorer > User Manager > Add other... > Java Action,在点选Java Action 後会跳出下列命名的视窗
按OK後会自动开启新的档案,这里可以让我们设定输出的parameters 和设定return type。
在设定parameter时,可以设定type和相关的category
有效的type选项有
• Object
• List
• Enumeration
• Boolean
• Date and time
• Decimal
• Integer/Long
• String
• Nothing
1.选择 Project > Deploy for Eclipse,之後系统会自动将source code档案存在project资料夹中
2.开启Eclipse後,可以在package explorer 中的 javasource > usermanager.actions 找到档案
Mendix 会自动生成档案,格式如下:
// 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 usermanager.actions;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
public class Java_action extends CustomJavaAction<java.util.List<IMendixObject>>
{
public Planner(IContext context)
{
super(context);
}
@java.lang.Override
public java.util.List<IMendixObject> executeAction() throws Exception
{
// BEGIN USER CODE
throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Java action was not implemented");
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "Java_action";
}
// BEGIN EXTRA CODE
// BEGIN EXTRA CODE
}
要注意,编写的部分要在 // BEGIN USER CODE
与 // END USER CODE
或 // BEGIN EXTRA CODE
与 // BEGIN EXTRA CODE
之间!
3.要连结Domain model中的实体(entity)时,需使用Mendix设定好的proxies,这可以在javasource > usermanager.proxies 找到,另外,每个实体在IMendixObject中都有自己的constructors、 getters和 setters 可以使用
// 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 usermanager.actions;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
public class Java_action extends CustomJavaAction<java.util.List<IMendixObject>>
{
private IMendixObject __Parameter;
private usermanager.proxies.Employee Parameter;
private IMendixObject __Parameter_2;
public Planner(IContext context, IMendixObject Parameter, IMendixObject Parameter_2)
{
super(context);
this.__Parameter = Parameter;
this.__Parameter_2 = Parameter_2;
}
@java.lang.Override
public java.util.List<IMendixObject> executeAction() throws Exception
{
this.Parameter = __Parameter == null ? null : usermanager.proxies.Employee.initialize(getContext(), __Parameter);
// BEGIN USER CODE
throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Java action was not implemented");
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "Java_action";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}
这篇文章只有简单介绍Mendix上的Java使用方式,但其实Mendix上的Java有很多不同的使用方法,关於更深入的Java使用方式可以参考官方文件。
<<: [LeetCode30] Day26 - 1106. Parsing A Boolean Expression
如何实现在callback中加入类的function; 比如一个界面的button,点击之後,需要调...
身为一名工程师,将文字编辑器打造出具个人风格也是理所当然的。VSCode 是现在主流的文字编辑器,也...
因为专案刚好需要用到 所以纪录一下参数在哪边 纪录一下 使用Visual Studio Entity...
程序语言百百种,C++的优势在哪? C++是一种使用广泛的电脑程序设计语言,继承C语言数据类型丰富、...
能够载入与以动作触发声音 能够使用图片结合物件互动 了解如何解构图片为粒子跟像素 了解如何将影片放...