In this tutorial, we will following the guideline of developing a plugin to develop our File Link Datalist Formatter. Please also refer to the very first tutorial How to develop a Bean Shell Hash Variable for more details steps.
1. What is the problem?
We have a file uploaded using File Upload field in form. We want to show the file name as a link to download the file in our datalist.
2. What is your idea to solve the problem?
We can develop a Datalist Column Formatter Plugin to convert the value to a link.
3. What is the input needed for your plugin?
The file download link format of Joget Workflow is
From the link format, we need to get the following information from admin user.
- Form Id : the form that contains the File Upload field.
- Download as Attachment: Whether or not to add "?attachedment=true" in link.
4. What is the output and expected outcome of your plugin?
The file name is displayed as a link in Datalist.
5. Is there any resources/API that can be reuse?
We can refer to the File Upload Field on how to generate the download link of the file.
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 "file_link_datalist_formatter" 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 "FileLinkDatalistFormatter" class under "org.joget.tutorial" package. Then, extend the class with org.joget.apps.datalist.model.DataListColumnFormatDefault abstract class. Please refer to Datalist Column Formatter 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.
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/fileLinkDatalistFormatter.json". Let us create a directory "resources/properties" under "file_link_datalist_formatter/src/main" directory. After create the directory, create a file named "fileLinkDatalistFormatter.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.
c. Manage the dependency libraries of your plugin
Our plugin is using org.displaytag.util.LookupUtil and class, it required displaytag and jsp-api library. So, we have to add it 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 "file_link_datalist_formatter/src/main" directory. Then, create a "FileLinkDatalistFormatter.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 "file_link_datalist_formatter-5.0.0.jar" file is created under "file_link_datalist_formatter/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 CRUD in userview to test our plugin. In list, let configure the File Upload field column as following.
In the CRUD list, we can see our file name is converted to a link.
8. Take a step further, share it or sell it
You can download the source code from file_link_datalist_formatter.zip.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/.