cancel
Showing results for 
Search instead for 
Did you mean: 

Custom FormType help

tcheekva
Champ in-the-making
Champ in-the-making
I need the ability to have a multiple select enum type.  I am using Activiti embedded.  I have created a new form type and it does load properly.  My problem is when I declare the type in the designer and set the enum values they are not loaded.  Looking thru the code looks like it is hardcoded to only 'enum' type(then loads values).  Is there a way to have it set so that it looks for types that begin with 'enum'.  I have the ability to render the formtypes properly but as they do not retrieve the values from the xml it is not doing me much good.  I am only trying to get access to the other html properties that are not exposed.  For the 'enum' HTMLSelect i want to be able so enable multiple for some of them based on the formtype defined.  I have other formtypes that populate from the database just fine but really need some to populate from the xml also.  I will also be creating some of the other types like checkbox(enumcheckbox),radio(enumradio) etc that will also need to behave like enum, as we do our own rendering based on the typename.

public class EnumMultiFormType extends AbstractFormType {

  protected Map<String, String> values;

  public EnumMultiFormType(Map<String, String> values) {
    this.values = values;
  }

  public String getName() {
    return "enummulti";
  }
 
  @Override
  public Object getInformation(String key) {
    if (key.equals("values")) {
      return values;
    }
    return null;
  }

  @Override
  public Object convertFormValueToModelValue(String propertyValue) {
    validateValue(propertyValue);
    return propertyValue;
  }

  @Override
  public String convertModelValueToFormValue(Object modelValue) {
    if(modelValue != null) {
      if(!(modelValue instanceof String)) {
        throw new ActivitiIllegalArgumentException("Model value should be a String");
      }
      validateValue((String) modelValue);
    }
    return (String) modelValue;
  }
 
  protected void validateValue(String value) {
    if(value != null) {
      if(values != null && !values.containsKey(value)) {
        throw new ActivitiIllegalArgumentException("Invalid value for enum form property: " + value);
      }
    }
  }

}
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
The copying of the "values" from XML is done in the class org.activiti.engine.impl.form.FormTypes. An instance (or subclass) can be set on the processEngineConfiguration. You can create a custom instance of that class that actually uses the formValues that get passed in on the FormProperty instead of relying on the "default" mechanism of getting a type, which is a lookup based on type-id.