Joget Workflow v6 Released
Check out the latest Joget Workflow v6 for many new features and improvements in user experience (UX), app maintainability and performance.
In this tutorial, we will be following the guideline for developing a plugin to develop our JDBC Form Load Binder plugin. Please also refer to this tutorial, How to develop a Bean Shell Hash Variable and also a JDBC related plugin How to develop a JDBC Options Binder for more details steps.
For integration purpose, we would like to load our form data from a different database table instead of Joget form data table.
Joget Workflow has provided a plugin type called Form Load Binder Plugin. We will refer to the former to develop a plugin to support JDBC connection and custom query to load form data.
To develop a JDBC Load binder, we will need the JDBC connection setting and also the custom query to populate the form data based on primary key or foreign key (for Grid).
The query should also support a syntax to inject the primary key (For Form/Section) or foreign key (For Grid element)
All retrieved columns are auto mapped to the fields with column name equal to field id.
We can refer to the implementation of other available Form Load 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 tutorial is prepared with a Macbook Pro and Joget Source Code version 5.0.0. Please refer to Guideline for developing a plugin for other platform command.
Let say our folder directory is as follows.
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.
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.
We should get "BUILD SUCCESS" message shown in our terminal and a "jdbc_load_binder" folder created in "plugins" folder.
Open the maven project with your favour IDE. I will be using NetBeans.
Create a "JdbcLoadBinder" 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 Load Binder, we will need to implement org.joget.apps.form.model.FormLoadBinder interface. Then, we need to implement org.joget.apps.form.model.FormLoadElementBinder interface to make this plugin show as a selection in load binder select box and implement org.joget.apps.form.model.FormLoadMultiRowElementBinder interface to list it under the load binder select box of grid element.
Please refer to Form Load 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/jdbcLoadBinder.json". Let us create a directory "resources/properties" under "jdbc_load_binder/src/main" directory. After create the directory, create a file named "jdbcLoadBinder.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.
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 load method.
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.
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_load_binder/src/main" directory. Then, create a "JdbcLoadBinder.properties" file in the folder. In the properties file, let add all the message keys and its label as below.
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.
Let build our plugin. Once the building process is done, we will found a "jdbc_load_binder-5.0.0.jar" file is created under "jdbc_load_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 load firstName, lastName and email from dir_user table based on username to test the load binder.
Then, configure the load binder of the form to use JDBC Binder with the following query.
Let create an userview and drag a Form Menu element to display our form. Then, publish it and test our form with an "id" parameter.
Next, let add a grid element and test with the following query.
Let check our result again.
It works! Please remember test the other features of the plugin as well.
You can download the source code from jdbc_load_binder_src.zip.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/.