cancel
Showing results for 
Search instead for 
Did you mean: 

Adding configuration information to a FormProperty

joaquinb
Champ in-the-making
Champ in-the-making
I need to render (with ZK) a UserTask in an application reading collection of formPropertys.

I don't know if it's possible to create a new data type and adding configurations to an instance in a form of this datatype.

For example, starting at sample TextAreaFormType i need to configure number of rows and number of columns to show when render this type of data.

I think that only extend the class org.activiti.engine.impl.form.FormTypes and overriding function
public AbstractFormType parseFormPropertyType(FormProperty formProperty) .

I implemented this solution but I think it's very bad. I don't know how to add form attributes  with configuration because
needs to change FormProperty to read variable attributes from xml.
For example:

<activiti:formProperty id="tipoAreaTexto" name="Tipo area texto" type="textarea" variable="tipoAreaTexto" required="true"  rows="5">


Instead I added this solution using activiti:value tag xml:
       <activiti:formProperty id="tipoAreaTexto" name="Tipo area texto" type="textarea" variable="tipoAreaTexto" required="true">
          <activiti:value id="rows" name="10"></activiti:value>
        </activiti:formProperty>




1. Create a new class FormTypesExtended

import org.activiti.bpmn.model.FormProperty;
import org.activiti.bpmn.model.FormValue;
import org.activiti.engine.form.AbstractFormType;
import org.activiti.engine.impl.form.BooleanFormType;
import org.activiti.engine.impl.form.DateFormType;
import org.activiti.engine.impl.form.FormTypes;
import org.activiti.engine.impl.form.LongFormType;
import org.activiti.engine.impl.form.StringFormType;

public class FormTypesExtended extends FormTypes {

   public FormTypesExtended() {
      super.addFormType(new StringFormType());
      super.addFormType(new LongFormType());
      super.addFormType(new DateFormType("dd/MM/yyyy"));
      super.addFormType(new BooleanFormType());
   }

   @Override
   public AbstractFormType parseFormPropertyType(FormProperty formProperty) {

      if ("textarea".equals(formProperty.getType())) {

         Map values = new LinkedHashMap();
         Integer rows = new Integer(3);

         // Access formProperty values..
         for (FormValue formValue : formProperty.getFormValues()) {

            // Contains rows
            if ("rows".equals(formValue.getId())) {
               rows = Integer.parseInt(formValue.getName());
            }
         }

         // Create new type with rows..
         TextAreaFormActivitiType textAreaType = new TextAreaFormActivitiType();
         textAreaType.setRows(rows);

         return textAreaType;
      }

      return super.parseFormPropertyType(formProperty);
   }
}

2. Adding class TextAreaFormActivitiType
public class TextAreaFormActivitiType extends AbstractFormType {

   public static final String TYPE_NAME = "textarea";

   private Integer _rows = new Integer(0);

   public TextAreaFormActivitiType() {
   }

   public Integer getRows() {
      return this._rows;
   }

   public void setRows(Integer rows) {
      this._rows = rows;
   }
  …


3. adding configuration in spring-activiti.xml
  <bean id="formTypesExtended" class="com.inditex.tempe.activiti.types.FormTypesExtended">
  </bean>

 
  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="formTypes" ref="formTypesExtended" />





2 REPLIES 2

joaquinb
Champ in-the-making
Champ in-the-making
Sorry there is errors in previos text

I need to know if its posibble to add custom attributes to an AbstractFormType. Actually I do this job extending class FormTypes.

1. Adding my class TextAreaFormActivitiType  extending AbstractFormType with attribute of textarea rows.
<code>
import org.activiti.engine.form.AbstractFormType;

public class TextAreaFormActivitiType extends AbstractFormType {

public static final String TYPE_NAME = "textarea";

private Integer _rows = new Integer(0);

public TextAreaFormActivitiType() {
}

public Integer getRows() {
  return this._rows;
}

public void setRows(Integer rows) {
  this._rows = rows;
}

@Override
public String getName() {
  return TYPE_NAME;
}

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

}

@Override
public String convertModelValueToFormValue(Object modelValue) {
  return (String) modelValue;
}

}
</code>


2. Extending class FormTypes (FormTypesExtended).  I am using formValues elements to configure number of rows to print.

<code>
       <activiti:formProperty id="tipoAreaTexto" name="Tipo area texto" type="textarea" variable="tipoAreaTexto" required="true">
          <activiti:value id="rows" name="10"></activiti:value>
        </activiti:formProperty>

</code>

.. instead i would like to us this… :
<code>
       <activiti:formProperty id="tipoAreaTexto" name="Tipo area texto" type="textarea" variable="tipoAreaTexto" required="true"  rows="10"/>
</code>


<code>

public class FormTypesExtended extends FormTypes {

public FormTypesExtended() {
  super.addFormType(new StringFormType());
  super.addFormType(new LongFormType());
  super.addFormType(new DateFormType("dd/MM/yyyy"));
  super.addFormType(new BooleanFormType());
}

@Override
public AbstractFormType parseFormPropertyType(FormProperty formProperty) {

  if ("textarea".equals(formProperty.getType())) {

   Map values = new LinkedHashMap();
   Integer rows = new Integer(3);

   // Access formProperty values..
   for (FormValue formValue : formProperty.getFormValues()) {

    // Contains rows
    if ("rows".equals(formValue.getId())) {
     rows = Integer.parseInt(formValue.getName());
    }
   }

   // Create new type with rows..
   TextAreaFormActivitiType textAreaType = new TextAreaFormActivitiType();
   textAreaType.setRows(rows);

   return textAreaType;
  }

  return super.parseFormPropertyType(formProperty);
}
}
</code>





3. Adding configuration to spring-activiti.xml file.

<code>
   <!– adding this configuration to spring-activiti.xml –>
  <bean id="formTypesExtended" class="com.inditex.tempe.activiti.types.FormTypesExtended">


  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="formTypes" ref="formTypesExtended" />
     …

</code>

frederikherema1
Star Contributor
Star Contributor
The XML doesn't allow adding additional attributes, pluggability should be done the way you described above. The activity:* elements are restricted by the XSD