Search in sources :

Example 1 with FormFieldValidationConstraint

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());
}
Also used : Task(org.camunda.bpm.engine.task.Task) FormFieldValidationConstraint(org.camunda.bpm.engine.form.FormFieldValidationConstraint) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) FormField(org.camunda.bpm.engine.form.FormField) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 2 with FormFieldValidationConstraint

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;
}
Also used : FormFieldValidationConstraint(org.camunda.bpm.engine.form.FormFieldValidationConstraint) FormFieldImpl(org.camunda.bpm.engine.impl.form.FormFieldImpl) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) StartProcessVariableScope(org.camunda.bpm.engine.impl.el.StartProcessVariableScope) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 3 with FormFieldValidationConstraint

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);
    }
}
Also used : FormFieldValidationConstraint(org.camunda.bpm.engine.form.FormFieldValidationConstraint)

Example 4 with FormFieldValidationConstraint

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);
    }
}
Also used : FormFieldValidationConstraint(org.camunda.bpm.engine.form.FormFieldValidationConstraint)

Aggregations

FormFieldValidationConstraint (org.camunda.bpm.engine.form.FormFieldValidationConstraint)4 VariableScope (org.camunda.bpm.engine.delegate.VariableScope)1 FormField (org.camunda.bpm.engine.form.FormField)1 TaskFormData (org.camunda.bpm.engine.form.TaskFormData)1 StartProcessVariableScope (org.camunda.bpm.engine.impl.el.StartProcessVariableScope)1 FormFieldImpl (org.camunda.bpm.engine.impl.form.FormFieldImpl)1 Task (org.camunda.bpm.engine.task.Task)1 Deployment (org.camunda.bpm.engine.test.Deployment)1 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)1