Creating your own Default Form Values
From OpenKM version 7.1.38 the method changed by adding the uuid of the node. The old version of the method was:
void setDefaultValues(String grpName, List<FormElement> formElementList);
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 of "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 plugins system will try to load it from there. See the sample below:
Do not miss the tag @PluginImplementation otherwise the application plugin system will not be able to retrieve the new class.
More information at: Register a new plugin.
Method description
Method | Type | Description |
---|---|---|
setDefaultValues(String grpName, List<FormElement> formElementList) |
void |
The method sets defaults values for the form elements of the group. |
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
*/
@PluginImplementation
public 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
<?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="Fecha" type="date" name="okp:test.date"/>
</property-group>
</property-groups>