Description

  • org.joget.apps.form.service.FormUtil
  • Under wflow-core module
  • Utility methods for the Form module.

Code Sample

import org.joget.apps.app.dao.FormDefinitionDao;
import org.joget.apps.app.model.FormDefinition;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.Form;
import org.joget.apps.form.service.FormService;
import org.joget.apps.form.service.FormUtil;

AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
FormDefinitionDao formDefinitionDao = (FormDefinitionDao) AppUtil.getApplicationContext().getBean("formDefinitionDao");
FormService formService = (FormService) AppUtil.getApplicationContext().getBean("formService");
 
String id = "crm_account";
String appId = "crm";
Long appVersion = appService.getPublishedVersion(appId);
   
AppDefinition appDef = appService.getAppDefinition(appId, appVersion.toString());
FormDefinition formDef = formDefinitionDao.loadById(formId, appDef);
if (formDef != null) {
    //create the form
    Form form = (Form) formService.createElementFromJson(formDef.getJson(), true);
 
    //Find an element by field id
    Element e = FormUtil.findElement("accountName", form, null);
}

Fields

FORM_BUILDER_ACTIVE
public static final java.lang.String FORM_BUILDER_ACTIVE = "formBuilderActive";

Key used to sets the request attribute to indicate the current request is from form builder.

FORM_ERRORS_PARAM
public static final java.lang.String FORM_ERRORS_PARAM = "_FORM_ERRORS";

Key used to passes the form errors to the next submission for comparison.

FORM_META_ORIGINAL_ID
public static final java.lang.String FORM_META_ORIGINAL_ID = "_FORM_META_ORIGINAL_ID";

Key used to stores the form record id in a hidden field of a form

FORM_RESULT_LOAD_ALL_DATA
public static final java.lang.String FORM_RESULT_LOAD_ALL_DATA = "FORM_RESULT_LOAD_ALL_DATA";

Key used by Multi Paged Form to loads all the data from child forms.

PROPERTY_CLASS_NAME
public static final java.lang.String PROPERTY_CLASS_NAME = "className";

Key used to retrieves class name from properties

PROPERTY_CUSTOM_PROPERTIES
public static final java.lang.String PROPERTY_CUSTOM_PROPERTIES = "customProperties";

Prefix for a form id used to builds Hibernate Query (HQL) conditions 

PROPERTY_DATE_CREATED
public static final java.lang.String PROPERTY_DATE_CREATED = "dateCreated";

Key used to stores created data of a record

PROPERTY_DATE_MODIFIED
public static final java.lang.String PROPERTY_DATE_MODIFIED = "dateModified";

Key used to stores modified data of a record

PROPERTY_ELEMENT_UNIQUE_KEY
public static final java.lang.String PROPERTY_ELEMENT_UNIQUE_KEY = "elementUniqueKey";

Key used to to store a unique running number for element in properties

PROPERTY_ELEMENTS
public static final java.lang.String PROPERTY_ELEMENTS = "elements";

Key used to retrieves child elements for an element in json

PROPERTY_FORM_DEF_ID
public static final java.lang.String PROPERTY_FORM_DEF_ID = "formdefid";

Key used to retrieves form definition id from properties

PROPERTY_GROUPING
public static final java.lang.String PROPERTY_GROUPING = "grouping";

Key used to retrieves grouping from properties

PROPERTY_ID
public static final java.lang.String PROPERTY_ID = "id";

Key used to retrieves id from properties

PROPERTY_LABEL
public static final java.lang.String PROPERTY_LABEL = "label";

Key used to retrieves label from properties

PROPERTY_OPTIONS
public static final java.lang.String PROPERTY_OPTIONS = "options";

Key used to retrieves options from properties

PROPERTY_OPTIONS_DELIMITER
public static final java.lang.String PROPERTY_OPTIONS_DELIMITER = ";";

Delimiter used to separate options

PROPERTY_POST_PROCESSOR
public static final java.lang.String PROPERTY_POST_PROCESSOR = "postProcessor";

Key used to retrieves post processor tool from properties

PROPERTY_POST_PROCESSOR_RUN_ON
public static final java.lang.String PROPERTY_POST_PROCESSOR_RUN_ON = "postProcessorRunOn";

Key used to retrieves running mode of a post processor from properties

PROPERTY_PROPERTIES
public static final java.lang.String PROPERTY_PROPERTIES = "properties";

Key used to retrieves element properties from json

PROPERTY_READONLY
public static final java.lang.String PROPERTY_READONLY = "readonly";

Key used to retrieves readonly from properties

PROPERTY_READONLY_LABEL
public static final java.lang.String PROPERTY_READONLY_LABEL = "readonlyLabel";

Key used to retrieves display readonly as label from properties

PROPERTY_SELECTED
public static final java.lang.String PROPERTY_SELECTED = "selected";

Key used to retrieves selected from properties

PROPERTY_TABLE_NAME
public static final java.lang.String PROPERTY_TABLE_NAME = "tableName";

Key used to retrieves table name from json

PROPERTY_TEMP_FILE_PATH
public static final java.lang.String PROPERTY_TEMP_FILE_PATH = "_tempFilePathMap";

Key used to stores the paths of uploaded temporary files

PROPERTY_VALIDATOR
public static final java.lang.String PROPERTY_VALIDATOR = "validator";

Key used to retrieves validator from json

PROPERTY_VALUE
public static final java.lang.String PROPERTY_VALUE = "value";

Key used to retrieves value from properties

Methods

clearProcessedFormJson
public static void clearProcessedFormJson() 

Used by system to clears the current processing form json in current thread

executeActions
public static org.joget.apps.form.model.FormData executeActions(org.joget.apps.form.model.Form form, org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Utility method to recursively find and invoke actions starting from an element.

executeElementFormatData
public static org.joget.apps.form.model.FormData executeElementFormatData(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Utility method to recursively find and invoke the formatData method starting from an element.

Return a java.util.Map mapping a binder to FormRowSets containing formatted values from all elements.

executeElementFormatDataForValidation
public static org.joget.apps.form.model.FormData executeElementFormatDataForValidation(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Utility method to recursively find and invoke the formatDataForValidation method starting from an element.

executeLoadBinders
public static org.joget.apps.form.model.FormData executeLoadBinders(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Utility method to recursively traverse and invoke load binders starting from an element.

executeOptionBinders
public static org.joget.apps.form.model.FormData executeOptionBinders(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Utility method to recursively find and invoke option binders starting from an element.

executePostFormSubmissionProccessor
public static void executePostFormSubmissionProccessor(org.joget.apps.form.model.Form form, org.joget.apps.form.model.FormData formData)

Utility methods to execute tool after form submission

executeValidators
public static boolean executeValidators(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Utility method to recursively find and invoke validators starting from an element.

findAndParseElement
public static org.joget.apps.form.model.Element findAndParseElement(java.lang.String json, java.lang.String fieldId)

Finds and parses the form field element from form json by field id

findAndParseElementFromJsonObject
public static org.joget.apps.form.model.Element findAndParseElementFromJsonObject(org.json.JSONObject obj, java.lang.String fieldId) throws java.lang.Exception

Finds and parses the form field element from form json object by field id

findElement
public static org.joget.apps.form.model.Element findElement(java.lang.String id, org.joget.apps.form.model.Element rootElement, org.joget.apps.form.model.FormData formData)

Utility method to recursively find an element by ID.

findElement
public static org.joget.apps.form.model.Element findElement(java.lang.String id, org.joget.apps.form.model.Element rootElement, org.joget.apps.form.model.FormData formData, java.lang.Boolean includeSubForm) 

Utility method to recursively find an element by ID.

findLoadBinder
public static org.joget.apps.form.model.FormLoadBinder findLoadBinder(org.joget.apps.form.model.Element element)

Utility method to recursively find the nearest ancestor load binder for an element.

findOptionsBinder
public static org.joget.apps.form.model.FormLoadBinder findOptionsBinder(org.joget.apps.form.model.Element element)

Utility method to recursively find the nearest ancestor options binder for an element.

findRootForm
public static org.joget.apps.form.model.Form findRootForm(org.joget.apps.form.model.Element element)

Utility method to recursively find the parent Form for an element.

findStoreBinder
public static org.joget.apps.form.model.FormStoreBinder findStoreBinder(org.joget.apps.form.model.Element element)

Utility method to recursively find the nearest ancestor store binder for an element.

generateDefaultForm
public static java.lang.String generateDefaultForm(java.lang.String formId, org.joget.apps.app.model.FormDefinition formDef)

Utility method used to creates a new form definition json

generateDefaultForm
public static java.lang.String generateDefaultForm(java.lang.String formId, org.joget.apps.app.model.FormDefinition formDef, org.joget.apps.app.model.FormDefinition copyFormDef)

Utility method used to creates a new form definition json based on another form definition

generateDefaultTemplateDataModel
public static java.util.Map generateDefaultTemplateDataModel(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Generates a standard map of data to be used within an element template.

generateElementHtml
public static java.lang.String generateElementHtml(final org.joget.apps.form.model.Element element, final org.joget.apps.form.model.FormData formData, final java.lang.String templatePath, java.util.Map dataModel)

Generates HTML output using a FreeMarker template.

generateElementJson
public static java.lang.String generateElementJson(org.joget.apps.form.model.Element element) throws java.lang.Exception

Generates JSON representing an element.

generateElementJsonObject
public static org.json.JSONObject generateElementJsonObject(org.joget.apps.form.model.Element element) throws java.lang.Exception

Generates a JSONObject to represent an element

generateElementMetaData
public static java.lang.String generateElementMetaData(org.joget.apps.form.model.Element element)

Generates the HTML tag meta data for the element that is used by the form builder.

generateElementPropertyJson
public static java.lang.String generateElementPropertyJson(org.joget.apps.form.model.Element element)

Generates JSON representing the properties of an element.

generateElementPropertyValues
public static java.lang.String generateElementPropertyValues(java.lang.String[] values)

Generates a delimited string from an array of Strings.

generatePropertyJsonObject
public static org.json.JSONObject generatePropertyJsonObject(Map<java.lang.String, java.lang.Object> properties) throws org.json.JSONException

Generates a org.json.JSONObject to represent the properties of an element

getAjaxOptionsBinderData
public static org.joget.apps.form.model.FormRowSet getAjaxOptionsBinderData(java.lang.String dependencyValue, org.joget.apps.app.model.AppDefinition appDef, java.lang.String nonce, java.lang.String binderData)

Gets data from Options Binder for AJAX call

getApplicationContext
public static org.springframework.context.ApplicationContext getApplicationContext()

Utility method to retrieve the ApplicationContext of the system

getElementError
public static java.lang.String getElementError(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Retrieve the error attached to the element

getElementParameterName
public static java.lang.String getElementParameterName(org.joget.apps.form.model.Element element)

Returns the parameter name for the element.

getElementProcessedJson
public static java.lang.String getElementProcessedJson(org.joget.apps.form.model.Element element)

Utility method to convert an element to json

getElementPropertyOptionsMap
public static java.util.Collection<java.util.Map> getElementPropertyOptionsMap(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Retrieves the property options for an element, first from the element's options binder. If no binder is available, the default options are used.

getElementPropertyValue
public static java.lang.String getElementPropertyValue(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Retrieves the property value for an element, first from the element's load binder. If no binder is available, the default value is used.
Overrides the binder/default value when value from request parameter is available.

getElementPropertyValues
public static java.lang.String[] getElementPropertyValues(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Retrieves the property value for an element, first from the element's load binder. If no binder is available, the default value is used.
Overrides the binder/default value when value from request parameter is available.
This method supports multiple values for a property.

getElementValidatorDecoration
public static java.lang.String getElementValidatorDecoration(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Retrieve a decoration on an element by any attached validator, e.g. marking a required field.

getFormColumns
public static java.util.Collection<java.util.Map<java.lang.String, java.lang.String>> getFormColumns(org.joget.apps.app.model.AppDefinition appDef, java.lang.String formId)

Retrieve all form fields id & label in form data table

getProcessedFormJson
public static java.lang.String getProcessedFormJson()

Used by system to gets the current processing form json in current thread

getRequestParameter
public static java.lang.String getRequestParameter(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Returns the request parameter value for an element

getRequestParameterValues
public static java.lang.String[] getRequestParameterValues(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData) 

Returns the request parameter value for an element

getUniqueKey
public static java.lang.String getUniqueKey()

Gets a running number a unique key

isAjaxOptionsSupported
public static boolean isAjaxOptionsSupported(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Check the element is using Ajax to load options 

isElementPropertyValuesChanges
public static boolean isElementPropertyValuesChanges(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData, java.lang.String[] updatedValues)

Utility methods to check the value of an element is changed

isFormBuilderActive
public static boolean isFormBuilderActive()

Check whether request is currently in the form builder.

isFormSubmitted
public static boolean isFormSubmitted(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Check a form is submitted or not

isReadonly
public static boolean isReadonly(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Check an element is readonly or not

loadFormData
public static java.util.Map<java.lang.String, java.lang.Object> loadFormData(final java.lang.String appId, final java.lang.String appVersion, final java.lang.String formDefId, final java.lang.String primaryKeyValue, final boolean includeSubformData, final boolean includeReferenceElements, final boolean flatten, final org.joget.workflow.model.WorkflowAssignment assignment)

Utility method to fetch submitted form data values including data from subforms, and reference fields.
Returns a key-value pair (optionally flattened) for all the data that is part of a form submission.
The returned data includes top level form data, subform data (including recursive subforms), and data pointed by reference fields (like SelectBox pointing to a datalist item)

Parameters:
includeSubformData - true to recursively include subform data
includeReferenceElements - true to include data from reference elements e.g. selectbox, etc.
flatten - true to flatten data into a one level key-value map
assignment - Optional workflow assignment (for assignment hash variables)
Return a java.util.Map<java.lang.String,Object> representing the form data. The key is the element ID, and the value is either a java.lang.String for an element value, java.util.Map<java.lang.String,Object> representing subform data, or java.util.Collection<java.util.Map<java.lang.String,Object>> for reference fields.

loadFormDataJson
public static java.lang.String loadFormDataJson(java.lang.String appId, java.lang.String appVersion, java.lang.String formDefId, java.lang.String primaryKeyValue, boolean includeSubformData, boolean includeReferenceElements, boolean flatten, org.joget.workflow.model.WorkflowAssignment assignment) throws org.json.JSONException

Similar to loadFormData, returns results in JSON format.

parseBinderFromJsonObject
public static org.joget.apps.form.model.FormBinder parseBinderFromJsonObject(org.json.JSONObject obj, org.joget.apps.form.model.Element element, java.lang.String binderType) throws java.lang.Exception

Parse binder object from element json object

parseChildElementsFromJsonObject
public static void parseChildElementsFromJsonObject(org.json.JSONObject obj, org.joget.apps.form.model.Element parent) throws java.lang.Exception

Parse child elements from element json object

parseElementFromJson
public static org.joget.apps.form.model.Element parseElementFromJson(java.lang.String json) throws java.lang.Exception

Parses form field element from the element json string

parseElementFromJsonObject
public static org.joget.apps.form.model.Element parseElementFromJsonObject(org.json.JSONObject obj, org.joget.apps.form.model.Element parent) throws java.lang.Exception

Parses form field element from the element json object

parsePropertyFromJsonObject
public static java.util.Map<java.lang.String, java.lang.Object> parsePropertyFromJsonObject(org.json.JSONObject obj) throws org.json.JSONException 

Parses the properties attribute from a JSON object into a Map

parseValidatorFromJsonObject
public static org.joget.apps.form.model.Validator parseValidatorFromJsonObject(org.json.JSONObject obj) throws java.lang.Exception 

Parse validator object from element json object

setAjaxOptionsElementProperties
public static void setAjaxOptionsElementProperties(org.joget.apps.form.model.Element element, org.joget.apps.form.model.FormData formData)

Sets security data for multi options element which using Ajax call to load options

setFormBuilderActive
public static void setFormBuilderActive(java.lang.Boolean active)

Sets flag in request to indicate whether is currently in the form builder.

setProcessedFormJson
public static void setProcessedFormJson(java.lang.String json)

Used by system to sets the current processing form json in current thread

setReadOnlyProperty
public static void setReadOnlyProperty(org.joget.apps.form.model.Element element)

Recursively set the readonly property for all descendent elements.

setReadOnlyProperty
public static void setReadOnlyProperty(org.joget.apps.form.model.Element element, java.lang.Boolean readonly, java.lang.Boolean label) 

Recursively set the readonly property for all descendent elements.

  • No labels