Camunda Custom Form Field Type

时间:2016-04-25 08:51:13

标签: camunda

We are implementing Camunda on our application and we have a problem with forms

We need to implement our own form field type. We use the Camunda Modeler and use the custom type in the Type attribute of the field but when we try to deploy the war we always see the same error

ENGINE-16004 Exception while closing command context: ENGINE-09005 Could not parse BPMN process. Errors:
* unknown type 'file' [...]

We searched in the documentation but we don't see how to implement custom form field types

Any idea how to solve this?

Thanks in advance

2 个答案:

答案 0 :(得分:1)

您没有提供有关项目的更多信息以及如何尝试在嵌入式中使用自定义类型?任务表单。 Camunda有一个很好的例子,如何在这里使用嵌入式TaskForms: https://github.com/camunda/camunda-bpm-examples/tree/master/usertask/task-form-embedded-serialized-java-object

答案 1 :(得分:0)

生成的表单中的自定义类型用于可以呈现为单个html输入字段的值的类型,呈现复杂的结构(如表或bean属性的多个输入)没有用。

https://forum.camunda.org/t/camunda-custom-form-field-type/501描述了自定义类型的工作方式:

自定义类型必须扩展AbstractFormFieldType,以提供模型类型和表单显示类型之间的映射,有关示例,请参见DateTypeValue。然后,您必须在ProcessEnginePlugin which has access to the bpm engine configuration中使用ProcessEngineConfiguration.setCustomFormTypes()向bpmn引擎告知您的自定义类型。

生成的表单会将表单显示类型呈现为单个输入字段,只有替代方法是datepicker表示日期,并选择枚举,如您在HtmlFormEngine#renderFormField中看到的那样:

if(isEnum(formField)) {
  // <select ...>
  renderSelectBox(formField, documentBuilder);

} else if (isDate(formField)){

  renderDatePicker(formField, documentBuilder);

} else {
  // <input ...>
  renderInputField(formField, documentBuilder);

}

这是org.camunda.bpm.engine.impl.form.engine.HtmlFormEngine#renderInputField,它呈现一个输入:

protected void renderInputField(FormField formField, 
      HtmlDocumentBuilder documentBuilder) {

  HtmlElementWriter inputField = new HtmlElementWriter(INPUT_ELEMENT, true);
  addCommonFormFieldAttributes(formField, inputField);

  String inputType = !isBoolean(formField) ? TEXT_INPUT_TYPE : CHECKBOX_INPUT_TYPE;

  inputField.attribute(TYPE_ATTRIBUTE, inputType);

  // add default value
  Object defaultValue = formField.getDefaultValue();
  if(defaultValue != null) {
    inputField.attribute(VALUE_ATTRIBUTE, defaultValue.toString());
  }

  // <input ... />
  documentBuilder.startElement(inputField).endElement();
}
相关问题