AnsweredAssumed Answered

Custom FormType help

Question asked by tcheekva on May 21, 2013
Latest reply on May 22, 2013 by frederikheremans1
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);
      }
    }
  }

}

Outcomes