Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this tutorial, we will following follow the guideline of developing a plugin to develop our Download PDF Datalist Action plugin. 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 need to provide a PDF download feature when user click on a link/button on a datalist. The downloaded PDF file should be a form with data populatedrequire the ability to download form data as a PDF file from the datalist.

2.

...

How to solve the problem?

We can will develop a Datalist Action Plugin to display a button for to generate a form PDF file. 

...

To develop a PDF Download Datalist Action plugin, we can will consider to provide providing the following as input.

  1. Form ID : The form that will be used to generate the PDF file.
  2. Record ID Column : Use the id of the datalist row or a column value to load the record.
  3. Formatting options : Options to format and customise the PDF output. 

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

When the PDF Download Datalist Action is used as a datalist row action or column action, a normal user will see a link to download the PDF file in every rows row of a the datalist. Once the link is clicked, a PDF file will be prompt to downloadprompted for downloaded for that specific row.

When the plugin is used as whole datalist actionfor multiple datalist rows (whole list action), a zip file containing all the generated PDF PDFs of every selected rows will be prompt to prompted for download when the button is clicked.

5. Is there any resources/API that can be

...

reused?

To develop the PDF Download Datalist Action plugin, we can reuse the methods in FormPdfUtil to generate a form as PDF. We can also refer to the source code of the Datalist Form Data Delete Action plugin as well. Other than that, we can refer to the Export Form Email Tool on what kind of plugin properties options we can provide in the plugin as the Export Form Email Tool are using the methods in FormPdfUtil as well.

...

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 the Joget Source Code is version 5.0.0. Please refer to to the Guideline of for developing a plugin for article for other platform commandcommands.

Let said 's say our folder directory is as followingfollows

Code Block
- 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 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 your the plugin and ask us for a confirmation before generate it generates the maven project.

Code Block
languagebash
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: download_pdf_datalist_action
version: 5.0.0
package: org.joget.tutorial
Y: : y

We should get a "BUILD SUCCESS" message shown in our terminal and a "download_pdf_datalist_action" folder created in the "plugins" folder.

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

...

Code Block
languagejava
titleImplementation of all basic abstract methods
collapsetrue
package org.joget.tutorial;
 
import org.joget.apps.app.service.AppPluginUtil;
import org.joget.apps.datalist.model.DataListActionDefault;
 
public class DownloadPdfDatalistAction extends DataListActionDefault {
    
    private final static String MESSAGE_PATH = "messages/DownloadPdfDatalistAction";
 
    public String getName() {
        return "Download PDF Datalist Action";
    }
    public String getVersion() {
        return "5.0.0";
    }
    
    public String getClassName() {
        return getClass().getName();
    }
    
    public String getLabel() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.DownloadPdfDatalistAction.pluginLabel", getClassName(), MESSAGE_PATH);
    }
    
    public String getDescription() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.DownloadPdfDatalistAction.pluginDesc", getClassName(), MESSAGE_PATH);
    }
 
    public String getPropertyOptions() {
        return AppUtil.readPluginResource(getClassName(), "/properties/downloadPdfDatalistAction.json", null, true, MESSAGE_PATH);
    }
 
    public String getLinkLabel() {
        return getPropertyString("label"); //get label from configured properties options
    }
 
    public String getHref() {
        return getPropertyString("href"); //Let system to handle to post to the same page
    }
 
    public String getTarget() {
        return "post";
    }
 
    public String getHrefParam() {
        return getPropertyString("hrefParam");  //Let system to set the parameter to the checkbox name
    }
 
    public String getHrefColumn() {
        String recordIdColumn = getPropertyString("recordIdColumn"); //get column id from configured properties options
        if ("id".equalsIgnoreCase(recordIdColumn) || recordIdColumn.isEmpty()) {
            return getPropertyString("hrefColumn"); //Let system to set the primary key column of the binder
        } else {
            return recordIdColumn;
        }
    }
 
    public String getConfirmation() {
        return getPropertyString("confirmation"); //get confirmation from configured properties options
    }
 
    public DataListActionResult executeAction(DataList dataList, String[] rowKeys) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

ThenNow, we have to do 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 locate located at "/properties/downloadPdfDatalistAction.json". Let us create a directory "resources/properties" under "download_pdf_datalist_action/src/main" directory. After create creating the directory, create a file named "downloadPdfDatalistAction.json" in the "properties" folder.

...

Code Block
languagejs
[{
    title : '@@datalist.downloadPdf.config@@',
    properties : [{
        name : 'label',
        label : '@@datalist.downloadPdf.label@@',
        type : 'textfield',
        value : '@@datalist.downloadPdf.download@@'
    },
    {
        name : 'formDefId',
        label : '@@datalist.downloadPdf.form@@',
        type : 'selectbox',
        options_ajax : '[CONTEXT_PATH]/web/json/console/app[APP_PATH]/forms/options',
        required : 'True'
    },
    {
        name : 'recordIdColumn',
        label : '@@datalist.downloadPdf.recordIdColumn@@',
        description : '@@datalist.downloadPdf.recordIdColumn.desc@@',
        type : 'textfield'
    },
    {
        name : 'confirmation',
        label : '@@datalist.downloadPdf.confirmationMessage@@',
        type : 'textfield'
    }]
},
{
    title : '@@datalist.downloadPdf.advanced@@',
    properties : [{
        name : 'formatting',
        label : '@@datalist.downloadPdf.formatting@@',
        type : 'codeeditor',
        mode : 'css'
    },
    {
        name : 'headerHtml',
        label : '@@datalist.downloadPdf.headerHtml@@',
        type : 'codeeditor',
        mode : 'html'
    },
    {
        name : 'repeatHeader',
        label : '@@datalist.downloadPdf.repeatHeader@@',
        type : 'checkbox',
        options : [{
            value : 'true',
            label : ''
        }]
    },
    {
        name : 'footerHtml',
        label : '@@datalist.downloadPdf.footerHtml@@',
        type : 'codeeditor',
        mode : 'html'
    },
    {
        name : 'repeatFooter',
        label : '@@datalist.downloadPdf.repeatFooter@@',
        type : 'checkbox',
        options : [{
            value : 'true',
            label : ''
        }]
    },
    {
        name : 'hideEmptyValueField',
        label : '@@datalist.downloadPdf.hideEmptyValueField@@',
        type : 'checkbox',
        options : [{
            value : 'true',
            label : ''
        }]
    },
    {
        name : 'showNotSelectedOptions',
        label : '@@datalist.downloadPdf.showNotSelectedOptions@@',
        type : 'checkbox',
        options : [{
            value : 'true',
            label : ''
        }]
    }]
}]

After done completing the properties option to collect input, we can work on the main method of the plugin which is executeAction method.

...

We are using i18n message key in getLabel and getDescription method. We also used i18n will use i18n message key in our properties options definition as well. SoThen, we will need to create a message resource bundle properties file for our plugin.

Create a directory, "resources/messages", under "download_pdf_datalist_action/src/main" directory. Then, create a "DownloadPdfDatalistAction.properties" file in the folder. In the properties file, let add all the message keys and its label as below.

Code Block
org.joget.tutorial.DownloadPdfDatalistAction.pluginLabel=Download PDF
org.joget.tutorial.DownloadPdfDatalistAction.pluginDesc=Support to download form PDF from datalist
datalist.downloadPdf.download=Download
datalist.downloadPdf.config=Configure Download PDF Action
datalist.downloadPdf.label=Label
datalist.downloadPdf.form=Form
datalist.downloadPdf.recordIdColumn=Record Id Column
datalist.downloadPdf.recordIdColumn.desc=Default to the primary key of the configured binder
datalist.downloadPdf.confirmationMessage=Confirmation Message
datalist.downloadPdf.hideEmptyValueField=Hide field that without value
datalist.downloadPdf.showNotSelectedOptions=Show unselected options for multi options field
datalist.downloadPdf.advanced=Advanced
datalist.downloadPdf.formatting=Formatting (CSS)
datalist.downloadPdf.headerHtml=Header (HTML)
datalist.downloadPdf.repeatHeader=Repeat header on every page?
datalist.downloadPdf.footerHtml=Footer (HTML)
datalist.downloadPdf.repeatFooter=Repeat footer on every page?

e. Register your plugin to the Felix Framework

We 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.

Code Block
languagejava
    public void start(BundleContext context) {
        registrationList = new ArrayList<ServiceRegistration>();
        //Register plugin here
        registrationList.add(context.registerService(DownloadPdfDatalistAction.class.getName(), new DownloadPdfDatalistAction(), null));
    }

 

f. Build it and

...

test

 

Let's build our plugin. Once the building process is done, we will found find a "download_pdf_datalist_action-5.0.0.jar" file is created under "download_pdf_datalist_action/target" directory.

Then, let's upload the plugin jar to Manage Plugins. After upload uploading the jar file, double check that the plugin is uploaded and activated correctly.

Then, Let let's try it in one of the datalist. You can find see our new plugin is shown under "Actions" in Datalist Builder.

Once we dragged drag and dropped drop the "Download PDF" action into the datalist builder canvas, we can edit the action. The following configuration page will be shown based on our properties option definition.

 

Let's add the "Download PDF" action as row action and also the whole list action for testing. We can see the "Download" button shown correctly in the userview as image screenshot below.

When row action is clicked, a pdf is downloaded.

...

When the whole list action is clicked, a zip file is downloaded.

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

...