Joget DX Preview Release Available for Download
Check out Joget DX, the next generation successor to Joget Workflow for faster, simpler digital transformation.
In this tutorial, we will follow the guideline for developing a plugin to develop our Hyperlink Options Filter plugin. Please also refer to the very first tutorial How to develop a Bean Shell Hash Variable for more details steps.
We want to have a filter similar to the following.
2. How to solve the problem?
We will develop a Datalist Filter Type Plugin to render our Hyperlink Options Filter.
To develop a Hyperlink Options Filter plugin, we will need to provide some inputs as following.
A list of hyperlinks which will list all the options with its data count. When click the hyperlink will filter the datalist.
Refer to Datalist Filter Type Plugin.
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 the Joget Source Code is version 5.0.1. Please refer to the Guideline for developing a plugin article for other platform commands.
Let's 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 is 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 number for the plugin and ask us for a confirmation before it generates the maven project.
We should get a "BUILD SUCCESS" message shown in our terminal and a "hyperlink_options_filter" folder created in the "plugins" folder.
Open the maven project with your favourite IDE. I will be using NetBeans.
Create a "HyperlinkOptionsFilter" class under "org.joget" package. Then, extend the class with org.joget.apps.datalist.model.DataListFilterTypeDefault abstract class. Please refer to Datalist Filter Type 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.
Now, we have to create 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/hyperlinkOptionsFilter.json". Let us create a directory "resources/properties" under "hyperlink_options_filter/src/main" directory. After creating the directory, create a file named "hyperlinkOptionsFilter.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.
After completing the properties option to collect input, we can work on the main methods of the plugin which are getTemplate and getQueryObject method. In getTemplate method, we will retrieve options and its count based on the configured plugin properties.
In the getTemplate, we specify the template file to "hyperlinkOptionsFilter.ftl". Let create this file under "hyperlink_options_filter/src/main/resources/templates" directory. Then, using FreeMaker syntax to construct our template as below:
We need to include "commons-collections" library in our POM file.
We are using i18n message key in getLabel and getDescription method. We will use i18n message key in our properties options definition as well. Then, we will need to create a message resource bundle properties file for our plugin.
Create a directory, "resources/message", under "hyperlink_options_filter/src/main" directory. Then, create a "HyperlinkOptionsFilter.properties" file in the folder. In the properties file, add all the message keys and its label as below.
Next, we will have to register our plugin class in the Activator class (Auto generated in the same class package) to tell the Felix Framework that this is a plugin.
Let's build our plugin. Once the building process is done, we will find a "hyperlink_options_filter-5.0.0.jar" file created under "hyperlink_options_filter/target" directory.
Then, let's upload the plugin jar to Manage Plugins. After uploading the jar file, double check that the plugin is uploaded and activated correctly.
Then, check the Hyperlink Options Filter is shown as a selection of filter type in the Datalist Builder.
Configure its properties.
Save the properties and check the filter is render in canvas as following.
Check and test the filter in datalist.
You can download the source code from hyperlink_options_filter_src.zip.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/. (Coming Soon)