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 JDBC Form Store Binder plugin. Please also refer to the very first tutorial How to develop a Bean Shell Hash Variable and also the following JDBC related plugin for more details steps.
For integration purpose, we would like to store our form data to a different database table instead of Joget form data table.
Joget Workflow has provided a plugin type called Form Store Binder Plugin. We will develop one to support JDBC connection and custom query to store form data.
To develop a JDBC Store binder, we will need the JDBC connection setting and also the custom query to store the form data based the collected form data.
We will have to support a syntax to inject the form data to the query. "{foreignKey}" can be used for Multi Rows storing.
Example: INSERT INTO app_fd_test VALUES ({id}, {name}, {email}, {phone}, {foreignKey});
All submitted data will store accordingly based on the check/insert/update query.
We can refer to the implementation of other available Form Store Binder plugins. Joget default datasource can be retrieve with AppUtil.getApplicationContext().getBean("setupDataSource").
We need to always have our Joget Workflow Source Code ready and builded by following this guideline.
The following of this tutorial is prepared with a Macbook Pro and Joget Source Code version 5.0.0. Please refer to Guideline of developing a plugin for other platform command.
Let said our folder directory as following.
- Home - joget - plugins - jw-community -5.0.0
The "plugins" directory is the folder we will create and store all our plugins and the "jw-community" directory is where the Joget Workflow Source code stored.
Run the following command to create a maven project in "plugins" directory.
cd joget/plugins/ ~/joget/jw-community/5.0.0/wflow-plugin-archetype/create-plugin.sh org.joget.tutorial jdbc_store_binder 5.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.
Define value for property 'version': 1.0-SNAPSHOT: : 5.0.0 [INFO] Using property: package = org.joget.tutorial Confirm properties configuration: groupId: org.joget.tutorial artifactId: jdbc_store_binder version: 5.0.0 package: org.joget.tutorial Y: : y
We should get "BUILD SUCCESS" message shown in our terminal and a "jdbc_store_binder" folder created in "plugins" folder.
Open the maven project with your favour IDE. I will be using NetBeans.
Create a "JdbcStoreBinder" class under "org.joget.tutorial" package. Then, extend the class with org.joget.apps.form.model.FormBinder abstract class.
To make it work as a Form Store Binder, we will need to implement org.joget.apps.form.model.FormStoreBinder interface. Then, we need to implement org.joget.apps.form.model.FormStoreElementBinder interface to make this plugin show as a selection in store binder select box and implement org.joget.apps.form.model.FormStoreMultiRowElementBinder interface to list it under the store binder select box of grid element.
Please refer to Form Store Binder Plugin.
As usual, we have to implement all the abstract methods. We will using AppPluginUtil.getMessage method to support i18n and using constant variable MESSAGE_PATH for message resource bundle directory.
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 locate at "/properties/jdbcStoreBinder.json". Let us create a directory "resources/properties" under "jdbc_store_binder/src/main" directory. After create the directory, create a file named "jdbcStoreBinder.json" in the "properties" folder.
In the properties definition options file, we will need to provide options as below. Please note that we can use "@@message.key@@" syntax to support i18n in our properties options.
[{ title : '@@form.jdbcStoreBinder.config@@', properties : [{ name : 'jdbcDatasource', label : '@@form.jdbcStoreBinder.datasource@@', type : 'selectbox', options : [{ value : 'custom', label : '@@form.jdbcStoreBinder.customDatasource@@' },{ value : 'default', label : '@@form.jdbcStoreBinder.defaultDatasource@@' }], value : 'default' },{ name : 'jdbcDriver', label : '@@form.jdbcStoreBinder.driver@@', description : '@@form.jdbcStoreBinder.driver.desc@@', type : 'textfield', value : 'com.mysql.jdbc.Driver', control_field: 'jdbcDatasource', control_value: 'custom', control_use_regex: 'false', required : 'true' },{ name : 'jdbcUrl', label : '@@form.jdbcStoreBinder.url@@', type : 'textfield', value : 'jdbc:mysql://localhost/jwdb?characterEncoding=UTF8', control_field: 'jdbcDatasource', control_value: 'custom', control_use_regex: 'false', required : 'true' },{ name : 'jdbcUser', label : '@@form.jdbcStoreBinder.username@@', type : 'textfield', control_field: 'jdbcDatasource', control_value: 'custom', control_use_regex: 'false', value : 'root', required : 'true' },{ name : 'jdbcPassword', label : '@@form.jdbcStoreBinder.password@@', type : 'password', control_field: 'jdbcDatasource', control_value: 'custom', control_use_regex: 'false', value : '' },{ name : 'check_sql', label : '@@form.jdbcStoreBinder.check_sql@@', description : '@@form.jdbcStoreBinder.check_sql.desc@@', type : 'codeeditor', mode : 'sql', required : 'true' },{ name : 'insert_sql', label : '@@form.jdbcStoreBinder.insert_sql@@', description : '@@form.jdbcStoreBinder.insert_sql.desc@@', type : 'codeeditor', mode : 'sql', required : 'true' },{ name : 'update_sql', label : '@@form.jdbcStoreBinder.update_sql@@', description : '@@form.jdbcStoreBinder.update_sql.desc@@', type : 'codeeditor', mode : 'sql', required : 'true' },{ name : 'autoId', label : '@@form.jdbcStoreBinder.autoId@@', type : 'checkbox', options : [{ value : 'true', label : '' }] }], buttons : [{ name : 'testConnection', label : '@@form.jdbcStoreBinder.testConnection@@', ajax_url : '[CONTEXT_PATH]/web/json/app[APP_PATH]/plugin/org.joget.tutorial.JdbcStoreBinder/service?action=testConnection', fields : ['jdbcDriver', 'jdbcUrl', 'jdbcUser', 'jdbcPassword'], control_field: 'jdbcDatasource', control_value: 'custom', control_use_regex: 'false' }] }]
Same as JDBC Options Binder, we will need to add a test connection button for custom JDBC setting. Please refer to How to develop a JDBC Options Binder on the Web Service Plugin implementation.
Once we done the properties option to collect input and the web service to test the connection, we can work on the main method of the plugin which is store method.