Take note of the "Post Processing Tool" attribute in a form builder's properties. We can see that it is listing down a list of Process Tool plugin for App Designer to choose.

จดบันทึกคุณสมบัติ "เครื่องมือประมวลผลภายหลัง" ในคุณสมบัติของเครื่องมือสร้างแบบฟอร์ม เราสามารถเห็นได้ว่ามันกำลังแสดงรายการปลั๊กอินเครื่องมือกระบวนการเพื่อให้ App Designer เลือก


Introducing the property definition type and configurations

แนะนำประเภทคำจำกัดความของคุณสมบัติและการกำหนดค่า

We can trace this behavior to the property definition file "form.json" - https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-core/src/main/resources/properties/form/form.json#L81

This is the excerpt of the file that is responsible to generate such dropdown selection.

You will need to include such definition in your plugin's property definition file.

เราสามารถติดตามพฤติกรรมนี้ไปยังไฟล์คำจำกัดความคุณสมบัติ "form.json" - https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-core/src/main/resources/properties/form/ form.json # L81 นี่เป็นส่วนที่ตัดตอนมาของไฟล์ที่รับผิดชอบในการสร้างตัวเลือกแบบเลื่อนลง คุณจะต้องรวมคำนิยามดังกล่าวในไฟล์คำจำกัดความคุณสมบัติของปลั๊กอิน

            {
                name:	'postProcessor',
                label:'@@form.form.postProcessor@@',
                type:'elementselect',
                options_ajax:'[CONTEXT_PATH]/web/property/json/getElements?classname=org.joget.plugin.base.ApplicationPlugin',
                url:'[CONTEXT_PATH]/web/property/json[APP_PATH]/getPropertyOptions',
                default_property_values_url: '[CONTEXT_PATH]/web/property/json[APP_PATH]/getDefaultProperties'
            }

Explanations on the property definition code

คำอธิบายเกี่ยวกับรหัสการกำหนดคุณสมบัติ

Line 4 - Attribute "type" with the value set to "elementselect" is important to tell the property editor on how to handle the selection. A new tab will be created automatically upon a selection made.

บรรทัด 4 - แอตทริบิวต์ "type" ที่มีค่าตั้งเป็น "elementselect" เป็นสิ่งสำคัญที่จะบอกตัวแก้ไขคุณสมบัติเกี่ยวกับวิธีจัดการกับสิ่งที่เลือก แท็บใหม่จะถูกสร้างขึ้นโดยอัตโนมัติเมื่อมีการเลือก


Line 5 - Attribute "options_ajax" with the service URL set is responsible to load all the plugin tied to "org.joget.plugin.base.ApplicationPlugin" (Process Tool) into the selection. You may change the value to load the appropriate type of plugin you want.

[CONTEXT_PATH] is a special variable that will be replaced automatically at runtime with the Joget web app context information. (e.g.  http://localhost:8080/jw )

บรรทัดที่ 5 - แอตทริบิวต์ "options_ajax" พร้อมชุด URL บริการรับผิดชอบโหลดปลั๊กอินทั้งหมดที่เชื่อมโยงกับ "org.joget.plugin.base.ApplicationPlugin" (เครื่องมือประมวลผล) ลงในส่วนที่เลือก คุณสามารถเปลี่ยนค่าเพื่อโหลดประเภทของปลั๊กอินที่คุณต้องการ [CONTEXT_PATH] เป็นตัวแปรพิเศษที่จะถูกแทนที่โดยอัตโนมัติในขณะทำงานด้วยข้อมูลบริบทของแอปพลิเคชันเว็บ Joget (เช่น http: // localhost: 8080 / jw)

Line 6 - With the value in Line 4 set, the property editor will make a call to this URL, passing along the selection made. (e.g. http://localhost:8080/jw/web/property/json/expenseclaim/1/getPropertyOptions?value=org.joget.apps.app.lib.EmailTool)

[CONTEXT_PATH] is a special variable that will be replaced automatically at runtime with the Joget webapp context information. (e.g.  http://localhost:8080/jw )

[APP_PATH] is a special variable that will be replaced automatically at runtime with the Joget App context information. (e.g. /expenseclaim/1)

บรรทัด 6 - ด้วยค่าในชุด Line 4 ตัวแก้ไขคุณสมบัติจะทำการเรียกไปยัง URL นี้ผ่านไปตามการเลือกที่ทำ (e.g. http://localhost:8080/jw/web/property/json/expenseclaim/1/getPropertyOptions?value=org.joget.apps.app.lib.EmailTool)

[CONTEXT_PATH] เป็นตัวแปรพิเศษที่จะถูกแทนที่โดยอัตโนมัติในขณะทำงานด้วยข้อมูลบริบทของ Jappet webapp (e.g.  http://localhost:8080/jw )

[APP_PATH] เป็นตัวแปรพิเศษที่จะถูกแทนที่โดยอัตโนมัติในขณะทำงานด้วยข้อมูลบริบทของ Joget App (e.g. /expenseclaim/1)

Line 7 - Attribute "default_property_values_url" is optional but recommended to be included. When a new tab is created for the configurations of the selected plugin, default values will be loaded to ease and shorten the time in configuring.

บรรทัด 7 - แอตทริบิวต์ "default_property_values_url" เป็นตัวเลือก แต่แนะนำให้รวม เมื่อแท็บใหม่ถูกสร้างขึ้นสำหรับการกำหนดค่าของปลั๊กอินที่เลือกค่าเริ่มต้นจะถูกโหลดเพื่อความสะดวกและลดระยะเวลาในการกำหนดค่า

After a selection is made

หลังจากทำการเลือกแล้ว

After a selection is made, we can then see a new tab is added. We can also see that there are default values being loaded because of the inclusion of attribute "default_property_values_url" earlier.

หลังจากทำการเลือกแล้วเราจะเห็นแท็บใหม่ถูกเพิ่ม นอกจากนี้เรายังสามารถเห็นได้ว่ามีการโหลดค่าเริ่มต้นเนื่องจากมีการรวมแอตทริบิวต์ "default_property_values_url" ไว้ก่อนหน้านี้

How to retrieve the configurations set and run the plugin?

จะเรียกคืนชุดการกำหนดค่าและเรียกใช้ปลั๊กอินได้อย่างไร

Using back the sample, we can refer to the code at https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-core/src/main/java/org/joget/apps/form/service/FormUtil.java#L1932. Refer to the code of the method "executePostFormSubmissionProccessor".

Essentially, we will just need these few lines in our own plugin to get it to work.

การใช้ตัวอย่างกลับมาเราสามารถอ้างถึงรหัสได้ที่ https://github.com/jogetworkflow/jw-community/blob/6.0-SNAPSHOT/wflow-core/src/main/java/org/joget/apps/form/service/FormUtil.java#L1932 อ้างถึงรหัสของวิธีการ "executePostFormSubmissionProccessor" โดยพื้นฐานแล้วเราจะต้องใช้สองสามบรรทัดในปลั๊กอินของเราเพื่อให้มันใช้งานได้

Object binderData = getProperty("postProcessor");
PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
if (binderData != null && binderData instanceof Map) {
	Map bdMap = (Map) binderData;
	if (bdMap != null && bdMap.containsKey("className") && !bdMap.get("className").toString().isEmpty()) {
		String className = bdMap.get("className").toString();
		Plugin p = pluginManager.getPlugin(className);
                        
    	Map propertiesMap = (Map) bdMap.get("properties");
		ApplicationPlugin appPlugin = (ApplicationPlugin) p;
                        
		if (appPlugin instanceof PropertyEditable) {
				((PropertyEditable) appPlugin).setProperties(propertiesMap);
		}
		appPlugin.execute(propertiesMap);
	}
}

If we need to grab the plugin's default properties or to inject appDef, request object, etc then these excerpts from the method "executePostFormSubmissionProccessor" becomes necessary.

ถ้าเราต้องการคว้าคุณสมบัติเริ่มต้นของปลั๊กอินหรือเพื่อฉีด appDef ร้องขอวัตถุ ฯลฯ ดังนั้นเนื้อหาที่ตัดตอนมาจากเมธอด "executePostFormSubmissionProccessor" จำเป็น

Map propertiesMap = null;
                        
//get form json again to retrieve plugin properties
FormDefinitionDao formDefinitionDao = (FormDefinitionDao) FormUtil.getApplicationContext().getBean("formDefinitionDao");
FormDefinition formDefinition = formDefinitionDao.loadById(form.getPropertyString(FormUtil.PROPERTY_ID), appDef);
if (formDefinition != null) {
	String json = formDefinition.getJson();
	JSONObject obj = new JSONObject(json);
	JSONObject objProperty = obj.getJSONObject(FormUtil.PROPERTY_PROPERTIES);
	if (objProperty.has(FormUtil.PROPERTY_POST_PROCESSOR)) {
		JSONObject objProcessor = objProperty.getJSONObject(FormUtil.PROPERTY_POST_PROCESSOR);
		json = objProcessor.getString(FormUtil.PROPERTY_PROPERTIES);
		propertiesMap = AppPluginUtil.getDefaultProperties(p, json, appDef, ass);
	}
}
if (propertiesMap == null) {
	propertiesMap = AppPluginUtil.getDefaultProperties(p, (Map) temp.get(FormUtil.PROPERTY_PROPERTIES), appDef, ass);
}
if (ass != null) {
	propertiesMap.put("workflowAssignment", ass);
}
propertiesMap.put("recordId", formData.getPrimaryKeyValue());
propertiesMap.put("pluginManager", pluginManager);
propertiesMap.put("appDef", appDef);
// add HttpServletRequest into the property map
try {
	HttpServletRequest request = WorkflowUtil.getHttpServletRequest();
	if (request != null) {
		propertiesMap.put("request", request);
	}
} catch (Exception e) {
	// ignore if class is not found
}