...
To develop a Mood Rating Form Field plugin, we will need to provide some standard inputs of for a Form Field element.
- Field Id
- Field Label
- Validator
- Readonly
- Workflow Variable
4. What is the output and expected outcome of your plugin?
A form field shown smiley shown selection of smiley images and its radio button.
5. Are there any resources/API that can be reused?
...
Code Block | ||
---|---|---|
| ||
@Override public String renderTemplate(FormData formData, Map dataModel) { String template = "moodRatingField.ftl"; // set value String value = FormUtil.getElementPropertyValue(this, formData); dataModel.put("value", value); String html = FormUtil.generateElementHtml(this, formData, template, dataModel); return html; } |
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.
In the renderTemplate, we specify the template file to "moodRatingField.ftl". Let create this file under "mood_rating/src/main/resources/templates" directory. The using FreeMaker syntax to construct our template as below:
Code Block | ||
---|---|---|
| ||
<div class="form-cell mood_rating" ${elementMetaData!}>
<label class="label">${element.properties.label} <span class="form-cell-validator">${decoration}</span><#if error??> <span class="form-error-message">${error}</span></#if></label>
<div class="form-cell-value" id="${elementParamName!}${element.properties.elementUniqueKey!}">
<#if !(request.getAttribute("org.joget.MoodRatingField")??) >
<style>
.mood_rating .tdstyle {text-align:center;width:20%;border:0px none transparent !important;}
</style>
</#if>
<table style="width:150px">
<tbody>
<tr>
<td class="tdstyle"><img height="25" width="25" src="${request.contextPath}/plugin/org.joget.MoodRatingField/images/smiley5.png"></td>
<td class="tdstyle"><img height="25" width="25" src="${request.contextPath}/plugin/org.joget.MoodRatingField/images/smiley4.png"></td>
<td class="tdstyle"><img height="25" width="25" src="${request.contextPath}/plugin/org.joget.MoodRatingField/images/smiley3.png"></td>
<td class="tdstyle"><img height="25" width="25" src="${request.contextPath}/plugin/org.joget.MoodRatingField/images/smiley2.png"></td>
<td class="tdstyle"><img height="25" width="25" src="${request.contextPath}/plugin/org.joget.MoodRatingField/images/smiley1.png"></td>
</tr>
<tr>
<#list ['5', '4', '3', '2', '1'] as i>
<td class="tdstyle">
<input grouping="${elementParamName!}" id="${elementParamName!}" name="${elementParamName!}" type="radio" value="${i}" <#if error??>class="form-error-cell"</#if> <#if element.properties.readonly! == 'true'> disabled</#if> <#if value?? && value == i>checked</#if> />
</td>
</#list>
</tr>
</tbody>
</table>
</div>
<div style="clear:both;"></div>
</div> |
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.
Create a directory, "resources/message/form", under "mood_rating/src/main" directory. Then, create a "MoodRatingField.properties" file in the folder. In the Create a directory, "resources/message/form", under "mood_rating/src/main" directory. Then, create a "MoodRatingField.properties" file in the folder. In the properties file, add all the message keys and its label as below.
...
Code Block | ||
---|---|---|
| ||
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.
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.
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.
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 Mood Rating field is shown in the Form Builder.
Drag it to the Form Builder Canvas and set its properties.
Save the properties and check the field is render in canvas as following.
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.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/. (Coming Soon)