Joget Workflow v6 Beta 4 Released

Check out the latest Joget Workflow v6 Beta for many new features and improvements in user experience (UX), app maintainability and performance.

Skip to end of metadata
Go to start of metadata

 

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.

1. What is the problem?

For integration purpose, we would like to store our form data to a different database table instead of Joget form data table.

2. What is your idea to solve the problem?

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.

3. What is the input needed for your plugin?

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.

  1. Datasource: Using custom datasource or Joget default datasource
  2. Custom JDBC Driver: The JDBC driver for custom datasource
  3. Custom JDBC URL: The JDBC connection URL for custom datasource
  4. Custom JDBC Username: The username for custom datasource
  5. Custom JDBC Password: The password for custom datasource
  6. SQL Check Exist Query: The query to check whether an insert or update query should be execute.
  7. SQL Insert Query: The query to insert form data. 
  8. SQL Update Query: The query to insert form data. 
  9. SQL Delete Query: The query to delete deleted form data when used as multirow binder.

We will have to support a syntax to inject the form data to the query. "{foreignKey}" can be used for Multi Rows storing.

We will also need to support a syntax to inject UUID value. In this case, we will use "{uuid}".

 Example: INSERT INTO app_fd_test VALUES ({id}, {name}, {email}, {phone}, {foreignKey});

4. What is the output and expected outcome of your plugin?

All submitted data will store accordingly based on the check/insert/update query.

5. Is there any resources/API that can be reuse?

We can refer to the implementation of other available Form Store Binder plugins. Joget default datasource can be retrieve with AppUtil.getApplicationContext().getBean("setupDataSource").

6. Prepare your development environment

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 for developing a plugin for other platform command.

Let said our folder directory as following. 

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_store_binder" folder created in "plugins" folder.

Open the maven project with your favour IDE. I will be using NetBeans.  

7. Just code it!

a. Extending the abstract class of a plugin type

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. 

b. Implement all the abstract methods

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.

 

Implementation of all basic abstract methods  Expand source

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.

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.

c. Manage the dependency libraries of your plugin

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.

d. Make your plugin internationalization (i18n) ready

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 "JdbcStoreBinder.properties" file in the folder. In the properties file, let add all the message keys and its label as below.

e. Register your plugin to Felix Framework

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.

f. Build it and testing

Let build our plugin. Once the building process is done, we will found a "jdbc_store_binder-5.0.0.jar" file is created under "jdbc_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 query.

Check Select Query
Insert Query

note: {uuid} can be used to generate a unique id

Update Query

 

Delete Query

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 test the other features of the plugin as well. (big grin)

8. Take a step further, share it or sell it

You can download the source code from jdbc_store_binder_src.zip

To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/.

 

  • No labels