Creating your own Default Form Values
You can create your own Default Form Values.
Conditions:
- The new Default Form Values class must implement the “FormDefaultValues” interface.
- The new Default Form Values class must be declared under the package “com.openkm.plugin.form.values”.
- The new Default Form Values class must be annotated with “@PluginImplementation”.
- The new Default Form Values class must extend “BasePlugin”.
Default Form Values interface:
package com.openkm.plugin.form.values;
import com.openkm.bean.form.FormElement;import net.xeoh.plugins.base.Plugin;
import java.util.List;
public interface FormDefaultValues extends Plugin {
String getName();
void setDefaultValues(String uuid, String grpName, List<FormElement> formElementList);}The new class must be loaded into the package com.openkm.plugin.form.values because the application’s plugin system will try to load it from there. See the sample below:
Method description
Section titled “Method description”| Method | Type | Description |
|---|---|---|
| setDefaultValues(String uuid, String grpName, List |
void | The method sets default values for the form elements of the group. |
Example of the default form values implementation
Section titled “Example of the default form values implementation”package com.openkm.plugin.form.values;
import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;import java.util.List;
import com.openkm.bean.form.FormElement;import com.openkm.bean.form.Input;import com.openkm.plugin.BasePlugin;
import net.xeoh.plugins.base.annotations.PluginImplementation;
/** * Implementation of default form values */@PluginImplementationpublic class FormDefaultValuesDate extends BasePlugin implements FormDefaultValues {
@Override public String getName() { return "Date Default Values"; }
@Override public void setDefaultValues(String uuid, String grpName, List<FormElement> formElementList) { if (grpName.equalsIgnoreCase("okg:test")) { for (FormElement element : formElementList) { if (element.getName().equals("okp:test.date")) { Input input = (Input) element; if (input.getValue().isEmpty()) { DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); Date date = new Date(); input.setValue(dateFormat.format(date)); } } } } }
}Metadata definition
Section titled “Metadata definition”<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 3.10//EN" "http://www.openkm.com/dtd/property-groups-3.10.dtd"><property-groups> <property-group label="Test" name="okg:test" defaultValueClassName="com.openkm.plugin.form.values.FormDefaultValuesDate"> <input label="Date" type="date" name="okp:test.date"/> </property-group></property-groups>