use of org.camunda.bpm.engine.form.FormFieldValidationConstraint in project camunda-bpm-platform by camunda.
the class FormDataTest method testGetFormFieldValidationConstraints.
@Deployment
public void testGetFormFieldValidationConstraints() {
runtimeService.startProcessInstanceByKey("FormDataTest.testGetFormFieldValidationConstraints");
Task task = taskService.createTaskQuery().singleResult();
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
List<FormField> formFields = taskFormData.getFormFields();
FormField field1 = formFields.get(0);
List<FormFieldValidationConstraint> validationConstraints = field1.getValidationConstraints();
FormFieldValidationConstraint constraint1 = validationConstraints.get(0);
assertEquals("maxlength", constraint1.getName());
assertEquals("10", constraint1.getConfiguration());
FormFieldValidationConstraint constraint2 = validationConstraints.get(1);
assertEquals("minlength", constraint2.getName());
assertEquals("5", constraint2.getConfiguration());
}
use of org.camunda.bpm.engine.form.FormFieldValidationConstraint in project camunda-bpm-platform by camunda.
the class FormFieldHandler method createFormField.
public FormField createFormField(ExecutionEntity executionEntity) {
FormFieldImpl formField = new FormFieldImpl();
// set id
formField.setId(id);
// set label (evaluate expression)
VariableScope variableScope = executionEntity != null ? executionEntity : StartProcessVariableScope.getSharedInstance();
if (label != null) {
Object labelValueObject = label.getValue(variableScope);
if (labelValueObject != null) {
formField.setLabel(labelValueObject.toString());
}
}
formField.setBusinessKey(businessKey);
// set type
formField.setType(type);
// set default value (evaluate expression)
Object defaultValue = null;
if (defaultValueExpression != null) {
defaultValue = defaultValueExpression.getValue(variableScope);
if (defaultValue != null) {
formField.setDefaultValue(type.convertFormValueToModelValue(defaultValue));
} else {
formField.setDefaultValue(null);
}
}
// value
TypedValue value = variableScope.getVariableTyped(id);
if (value != null) {
formField.setValue(type.convertToFormValue(value));
} else {
// first, need to convert to model value since the default value may be a String Constant specified in the model xml.
TypedValue typedDefaultValue = type.convertToModelValue(Variables.untypedValue(defaultValue));
// now convert to form value
formField.setValue(type.convertToFormValue(typedDefaultValue));
}
// properties
formField.setProperties(properties);
// validation
List<FormFieldValidationConstraint> validationConstraints = formField.getValidationConstraints();
for (FormFieldValidationConstraintHandler validationHandler : validationHandlers) {
// do not add custom validators
if (!"validator".equals(validationHandler.name)) {
validationConstraints.add(validationHandler.createValidationConstraint(executionEntity));
}
}
return formField;
}
use of org.camunda.bpm.engine.form.FormFieldValidationConstraint in project camunda-bpm-platform by camunda.
the class HtmlFormEngine method addCommonFormFieldAttributes.
protected void addCommonFormFieldAttributes(FormField formField, HtmlElementWriter formControl) {
String typeName = formField.getTypeName();
if (isEnum(formField) || isDate(formField)) {
typeName = StringFormType.TYPE_NAME;
}
typeName = typeName.substring(0, 1).toUpperCase() + typeName.substring(1);
String formFieldId = formField.getId();
formControl.attribute(CLASS_ATTRIBUTE, FORM_CONTROL_CLASS).attribute(NAME_ATTRIBUTE, formFieldId);
if (!formField.isBusinessKey()) {
formControl.attribute(CAM_VARIABLE_TYPE_ATTRIBUTE, typeName).attribute(CAM_VARIABLE_NAME_ATTRIBUTE, formFieldId);
} else {
formControl.attribute(CAM_BUSINESS_KEY_ATTRIBUTE, null);
}
// add validation constraints
for (FormFieldValidationConstraint constraint : formField.getValidationConstraints()) {
String constraintName = constraint.getName();
String configuration = (String) constraint.getConfiguration();
formControl.attribute(constraintName, configuration);
}
}
use of org.camunda.bpm.engine.form.FormFieldValidationConstraint in project camunda-bpm-platform by camunda.
the class AbstractRenderFormDelegate method addCommonFormFieldAttributes.
protected void addCommonFormFieldAttributes(FormField formField, HtmlElementWriter formControl) {
String typeName = formField.getTypeName();
if (isEnum(formField) || isDate(formField)) {
typeName = StringFormType.TYPE_NAME;
}
typeName = typeName.substring(0, 1).toUpperCase() + typeName.substring(1);
String formFieldId = formField.getId();
formControl.attribute(CLASS_ATTRIBUTE, FORM_CONTROL_CLASS).attribute(NAME_ATTRIBUTE, formFieldId).attribute(CAM_VARIABLE_TYPE_ATTRIBUTE, typeName).attribute(CAM_VARIABLE_NAME_ATTRIBUTE, formFieldId);
// add validation constraints
for (FormFieldValidationConstraint constraint : formField.getValidationConstraints()) {
String constraintName = constraint.getName();
String configuration = (String) constraint.getConfiguration();
formControl.attribute(constraintName, configuration);
}
}
Aggregations