Versions Compared

Key

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

...

In this tutorial, we will follow the guideline for developing a plugin to develop our Mood Rating Form Field plugin. Please also refer to the very first tutorial วิธีการพัฒนา Bean Shell Hash Variable for more details steps.

1. What is the problem?

We would like to have a rating field with some smiley images which can be reuse for other form.

2. How to solve the problem?

We will develop a Form Field Element Plugin to render our mood rating field. 

3. What is the input needed for your plugin?

To develop a Mood Rating Form Field plugin, we will need to provide some standard inputs for a Form Field element.

  1. Field Id
  2. Field Label
  3. Validator
  4. Readonly
  5. Workflow Variable

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

A form field shown selection of smiley images and its radio button.

5. Are there any resources/API that can be reused?

To develop the Mood Rating Form Field plugin, we can extends the Radio field in core product then replace its template and plugin properties options.

6. Prepare your development environment

We need to always have our Joget Workflow Source Code ready and builded by following this guideline

...

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

7. Just code it!

a. Extending the abstract class of a plugin type

Create a "MoodRatingField" class under "org.joget" package. Then, extend the class with org.joget.apps.form.lib.Radio class. The org.joget.apps.form.lib.Radio class is an implementation of org.joget.apps.form.model.Element abstract class. Please refer to Form Field Element 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.

...

There are some smiley image files will be used by the template, let put those image files under "mood_rating/src/main/resources/resources/image" directory.

c. Manage the dependency libraries of your plugin

There are no additional library needed.

d. Make your plugin internationalization (i18n) ready

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.

...

Code Block
org.joget.MoodRatingField.pluginLabel=Mood Rating
org.joget.MoodRatingField.pluginDesc=Form Field for rating mood
form.moodRating.config=Edit Mood Rating

e. Register your plugin to the Felix Framework

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(MoodRatingField.class.getName(), new MoodRatingField(), null));
    }

f. Build it and test

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

...

Check and test the field in form.

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

You can download the source code from mood_rating_src.zip.

...