Creating your own Default Form Values
To create your own default form values you must create a new class that implements the FormDefaultValues interface:
package com.openkm.plugin.form;
import com.openkm.bean.form.FormElement;
import net.xeoh.plugins.base.Plugin;
import java.util.List;
/**
* FormDefaultValues
*
*/
public interface FormDefaultValues extends Plugin {
String getName();
void setDefaultValues(String grpName, List<FormElement> formElementList);
}
The new class must be loaded into the package com.openkm.plugin.form because the application plugins system will 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 |
This method sets defaults values for the form elements of the group. |
Example of the default form values implementation
package com.openkm.plugin.form;
import com.openkm.bean.form.FormElement;
import com.openkm.bean.form.Input;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Formatter;
import java.util.List;
/**
* Implementation of default form values
*/
@PluginImplementation
public class FormDefaultValuesDate implements FormDefaultValues {
@Override
public String getName() {
return "Date Default Values";
}
@Override
public void setDefaultValues(String grpName, List<FormElement> formElementList) {
Formatter fmt = new Formatter();
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 2.8//EN" "http://www.openkm.com/dtd/property-groups-2.8.dtd">
<property-groups>
<property-group label="Test" name="okg:test" defaultValueClassName="com.openkm.plugin.form.FormDefaultValuesDate">
<input label="Fecha" type="date" name="okp:test.date"/>
</property-group>
</property-groups>