Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
In this tutorial, we will following the guideline of developing a plugin to develop our Multi Store Binder pluginmulti store binders plugin. Please also refer to the very first tutorial How to develop a Bean Shell Hash Variable and also the following store binder related plugin for more details detailed steps.
English |
---|
We would like to run multiple store binders plugins in a single store binder selection. This would open up more use cases with the ability to store form data into multiple destinations without the need for relying on other approaches such as JSON Tool or SOAP Tool. |
Joget Workflow has provided a plugin type called Form Store Binder Plugin. We will develop one based on this plugin category to support multiple selections and execution of store binders to store form data.
To develop a Multi Store binderbinders, we will need a multi-selector in a grid form and a text editor for additional notes for app designers.
Binders: Displays a list of store binders available.
Comments: Additional notes users might wish to add.
All submitted data will store accordingly based on the multiple selections configuration of each of the store binders selected.
We can refer to the implementation of other available Form Store Binder plugins. We can also refer to how Multi Tools plugin for the design:
...
We need to always have our Joget Workflow Source Code ready and built by following this guideline.
The following of this tutorial is prepared with Joget Source Code version 7.0.0. Please refer to Guideline for developing Developing a pluginPlugin for other platform commands.
Let said our folder directory as following's use the following folder structure.
Code Block |
---|
- Home - joget - plugins - jw-community -7.0.0 |
...
Code Block | ||
---|---|---|
| ||
cd joget/plugins/ ~/joget/jw-community/57.0.0/wflow-plugin-archetype/create-plugin.sh org.joget.tutorialmarketplace multi_store_binder 57.0.0 |
Then, the shell script will ask us to key in a version for your plugin and ask us for confirmation before generate the maven project.
Code Block | ||
---|---|---|
| ||
Define value for property 'version': 1.0-SNAPSHOT: : 7.0.0 [INFO] Using property: package = org.joget.tutorialmarketplace Confirm properties configuration: groupId: org.joget.tutorialmarketplace artifactId: multi_store_binder version: 7.0.0 package: org.joget.tutorialmarketplace Y: : y |
We should get the "BUILD SUCCESS" message shown in our terminal and a "multi_store_binder" folder created in the "plugins" folder.
Open the maven project with your favor favorite IDE. I We will be using NetBeans.
Create a "MultiStoreBinderMultiStoreBinders" class under "org.joget.tutorialmarketplace" package. Then, extend the class with org.joget.apps.form.model.FormBinder abstract class.
...
Please refer to Form Store Binder Plugin .
As usual, we have to implement all the abstract methods. We will be using the AppPluginUtil.getMessage method to support i18n and using the constant variable MESSAGE_PATH for the message resource bundle directory.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
package org.joget.tutorialmarketplace; import org.joget.apps.app.service.AppPluginUtil; import org.joget.apps.app.service.AppUtil; import org.joget.apps.form.model.Element; import org.joget.apps.form.model.FormBinder; import org.joget.apps.form.model.FormData; import org.joget.apps.form.model.FormRowSet; import org.joget.apps.form.model.FormStoreBinder; import org.joget.apps.form.model.FormStoreElementBinder; import org.joget.apps.form.model.FormStoreMultiRowElementBinder; public class MultiStoreBinderMultiStoreBinders extends FormBinder implements FormStoreBinder, FormStoreElementBinder, FormStoreMultiRowElementBinder { private final static String MESSAGE_PATH = "messages/multiStoreBindermultiStoreBinders"; public String getName() { return "Multimulti Storestore Binderbinders"; } public String getVersion() { return "7.0.0"; } public String getClassName() { return getClass().getName(); } public String getLabel() { //support i18n return AppPluginUtil.getMessage("org.joget.tutorialmarketplace.MultiStoreBinderMultiStoreBinders.pluginLabel", getClassName(), MESSAGE_PATH); } public String getDescription() { //support i18n return AppPluginUtil.getMessage("org.joget.tutorialmarketplace.MultiStoreBinderMultiStoreBinders.pluginDesc", getClassName(), MESSAGE_PATH); } public String getPropertyOptions() { return AppUtil.readPluginResource(getClassName(), "/properties/multiStoreBindermultiStoreBinders.json", null, true, MESSAGE_PATH); } public FormRowSet store(Element element, FormRowSet rows, FormData formData) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } } |
Then, we have to do a UI for admin user to provide inputs for our plugin. In getPropertyOptions method, we already specify our Plugin Properties Options definition file is located at "/properties/multiStoreBindermultiStoreBinders.json". Let us create a directory "resources/properties" under "multi_store_binder/src/main" directory. After creating the directory, create a file named "multiStoreBindermultiStoreBinders.json" in the "properties" folder.
...
Code Block | ||||
---|---|---|---|---|
| ||||
[ { "title" : "@@plugin.multistorebinder@@org.joget.marketplace.MultiStoreBinders.config@@", "properties" : [ { "name" : "binders", "label" : "@@plugin.multistorebinder@@org.joget.marketplace.MultiStoreBinders.storeBinder@@", "type" : "elementmultiselect", "options_ajax" : "[CONTEXT_PATH]/web/property/json/getElements?classname=org.joget.apps.form.model.FormStoreBinder&exclude=org.joget.sample.MultiStoreBinderMultiStoreBinders", "url" : "[CONTEXT_PATH]/web/property/json[APP_PATH]/getPropertyOptions", "default_property_values_url" : "[CONTEXT_PATH]/web/property/json[APP_PATH]/getDefaultProperties", "required" : "true" },{ "name" : "comment", "label" : "@@plugin.multistorebinder@@org.joget.marketplace.MultiStoreBinders.comment@@", "type" : "codeeditor" } ] } ] |
Same as Similar to the Multi Tool plugin, we will need a multi selector to list the available store binders excluding the multi store binderbinders. Refer to Plugin Properties Options#MultiselectinGridInterface(New)
...
Code Block | ||
---|---|---|
| ||
public FormRowSet store(Element element, FormRowSet rows, FormData formData) { final Object[] binders = (Object[]) getProperty("binders"); if (binders != null && binders.length > 0) { Thread newThread; final PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager"); newThread = new PluginThread(new Runnable() { public void run() { for (Object binder : binders) { if (binder != null && binder instanceof Map) { Map binderMap = (Map) binder; if (binderMap != null && binderMap.containsKey("className") && !binderMap.get("className").toString().isEmpty()) { String className = binderMap.get("className").toString(); FormStoreBinder p = (FormStoreBinder) pluginManager.getPlugin(className); if (p != null) { Map properties = new HashMap(); properties.putAll((Map) binderMap.get("properties")); if (p instanceof PropertyEditable) { ((PropertyEditable) p).setProperties(properties); } p.store(element, rows, formData); } } } } } }); newThread.start(); } return null; } |
Our plugin is using dbcp, javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse class, so we will need to add jsp-api and commons-dbcp library to our POM file.
Code Block | ||
---|---|---|
| ||
<!-- Change plugin specific dependencies here --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20080701</version> <scope>provided</scope> </dependency> <!-- End change plugin specific dependencies here --> |
We are using i18n message key in getLabel and getDescription method. We also used i18n message key in our properties options definition as well. So, we will need to create a message resource bundle properties file for our plugin.
Create directory "resources/messages" under "jdbc_store_binder/src/main" directory. Then, create a "multiStoreBindermultiStoreBinders.properties" file in the folder. In the properties file, let add all the message keys and its label as below.
Code Block | ||
---|---|---|
| ||
org.joget.marketplace.MultiStoreBinderMultiStoreBinders.pluginLabel=Multimulti Storestore Binderbinders org.joget.marketplace.MultiStoreBinderMultiStoreBinders.pluginDesc=Enable the use of multiple store binders plugin.multistorebinderorg.joget.marketplace.MultiStoreBinders.config=Configure Multimulti Storestore Binder plugin.multistorebinderbinders org.joget.marketplace.MultiStoreBinders.storeBinder=Store Binder plugin.multistorebinderBinders org.joget.marketplace.MultiStoreBinders.comment=Comment |
We will have to register our plugin class in Activator class (Auto generated in the same class package) to tell Felix Framework that this is a plugin.
Code Block | ||
---|---|---|
| ||
public void start(BundleContext context) { registrationList = new ArrayList<ServiceRegistration>(); //Register plugin here registrationList.add(context.registerService(MultiStoreBinderMultiStoreBinders.class.getName(), new MultiStoreBinderMultiStoreBinders(), null)); } |
Let build our plugin. Once the building process is done, we will found a "multi_store_binder-7.0.0.jar" file is created under the "multi_store_binder/target" directory.
Then, let upload the plugin jar to Manage Plugins. After upload, the jar file, double-check the plugin is uploaded and activated correctly.
Let create a form to create and update user to dir_user table.
Then, configure the store binder of the form with the following querysection to Default Form Binder and JDBC Binder.
Code Block | ||||
---|---|---|---|---|
| ||||
select username from dir_user where username = {id} |
Code Block | ||||
---|---|---|---|---|
| ||||
insert into dir_user (id, username, firstName, lastName, email, active) values ({id}, {id}, {firstName}, {lastName}, {email}, 1) |
...
Info | ||
---|---|---|
| ||
{uuid} can be used to generate a unique id |
Code Block | ||||
---|---|---|---|---|
| ||||
update dir_user set firstName = {firstName}, lastName = {lastName}, email = {email} where username = {id} |
...
Code Block | ||||
---|---|---|---|---|
| ||||
delete from TABLE_NAME where id = {id} |
Now, let test to add a user.
Check the user is created in dir_user table.
Let update the same record by pass the id in URL parameters.
Check the user is updated.
It works! Please remember to test the other features of the plugin as well.
You can download the source code from jdbcmulti_store_binder_src.zip
To download the ready-to-use plugin jar, please find it in at http://marketplace.joget.org/.
...