cancel
Showing results for 
Search instead for 
Did you mean: 

Extends EnumFormType

marcantoine
Champ in-the-making
Champ in-the-making
Hi,

I wan't to create a new custom form type.
I need a list a values (list of companies available on a database).
For that I want to create an type based on EnumFormType. I can create a new type in may form and it will appear correctly loaded (not via activiti-explorer but via activiti-rest - I think it's a library dependency problem for that)

But after looking the bpmn20.xml, the parameter will not have values. Is it possible to access to them using the Rest API ?

I have wrote this code:
import java.util.HashMap;import java.util.Map;import org.activiti.engine.ActivitiIllegalArgumentException;import org.activiti.engine.impl.form.EnumFormType;public class C4MCompaniesFormType extends EnumFormType {    static Map<String, String> getCompagnies(){     Map<String, String> companies;     companies = new HashMap<String, String>();     companies.put("companyId1", "Company name 1");     companies.put("companyId2", "Company Name 2");     return companies;  }    public C4MCompaniesFormType() {     super(getCompagnies());  }    public C4MCompaniesFormType(Map<String, String> companies) {   super(companies);  }    public String getName() {    return "companies";  }   @Override  public Object getInformation(String key) {     System.out.println( "getInformation : " + key );    if (key.equals("values")) {      return getCompagnies();    }    return null;  }    @Override  public Object convertFormValueToModelValue(String propertyValue) {   System.out.println( "convertFormValueToModelValue : " + propertyValue );   validateValue(propertyValue);   return propertyValue;  }   @Override  public String convertModelValueToFormValue(Object modelValue) {   System.out.println( "convertModelValueToFormValue : " + 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 company) {   Map<String, String> companies = getCompagnies();      if(company != null) {     if(companies != null && !companies.containsKey(company)) {       throw new ActivitiIllegalArgumentException("Invalid value for companies form property: " + company);     }   }  }}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍



Thanks,
8 REPLIES 8

jbarrez
Star Contributor
Star Contributor
Arter properties are submitted, they will be stored as regular process variables in your process instance. You can access them via the rest api as regular variables from that point on.

marcantoine
Champ in-the-making
Champ in-the-making
Hi Joram,

In fact the current problem is based on enum type.
I want to define a new Enum type named Companies to create a specific list.
but as i can see the code here: https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/...
Values in the form are only asked to the formType if the type name is "enum".

Is it possible to define the name as a companies but defined as an enum to get the call of the method: getInformation("values") ?

jbarrez
Star Contributor
Star Contributor
ok i see. Isn't it possible to register your own type with the 'formTypes' map above there?

If not, can you provide a bit of code here so we can try it out?

marcantoine
Champ in-the-making
Champ in-the-making
Hi,
I publish some code for that here:
https://github.com/MarcAntoine-Arnaud/activiti-tests

You can also found the jar in releases:
https://github.com/MarcAntoine-Arnaud/activiti-tests/releases

You can comment or send some pull request if you found some bad code 😉

marcantoine
Champ in-the-making
Champ in-the-making
I think the type of extended type are: "serializable"
Is it possible to overload somewhere the base type ?

marcantoine
Champ in-the-making
Champ in-the-making
I look on Activiti-Explorer and it work fine to list every values with this implementation.
But using the Rest-API with the call on:
<code>form/form-data?processDefinitionId=formExtension:2:60132</code>
values are empty.

Is it possible to create a patch to insert values here ?
I see in the code https://github.com/Activiti/Activiti/blob/master/modules/activiti-rest/src/main/java/org/activiti/re... who the method will call <code>getStartFormData(String processDefinitionId)</code>

And this code don't use the Property Renderer to get values.
Is it possible to have the best way to implement/update that and to send you a pull request ?

jbarrez
Star Contributor
Star Contributor
Hi Marc-Antoine,

Sorry for the delay, been traveling the last couple of days and zero time to check on this issue.

Okay, so you've done some nice investigation and you are right. The reason why it works in Explorer is because of the renderer that is used there. Now the problem is of course, we can't add the renderers to the  REST api, cause it used UI elements and it doesn't really 'render' anything.

So two things here:

- Is it a decision to use the form properties vs the form key approach? it seems you are not using Explorer, right? With the form key approach you're pretty open to do whatever you want (which is also what we use in the commercial Activiti product).

- I think the problem is actually this bit of code indeed: https://github.com/Activiti/Activiti/blob/master/modules/activiti-rest/src/main/java/org/activiti/re... . For enums, special care is taken, but not for custom types.

As a short term-workaround, have you tried to let the getName() method return 'enum', instead of 'compagnies' ?

<code>
public String getName() {
    return "enum";
  }
</code>

marcantoine
Champ in-the-making
Champ in-the-making
Hi Joram,
No problem about he delay 😉
I understand the problem around the rendering. I supposed that before but not sure.

What do ou mean by form key ? Because I set an formKey value to use form in start or user task.

Is it possible to define a template form and use it in workflows definitions ?
Do you have any simple example ?

The case to set the name with "enum", I have no idea how to consume this resource in the form instead the basic enum type.
And with the link you mentioned, it will be correct if we can overload the getType() method to return "enum" with a getName which return "companies" for example. But actually i's impossible.

And yes of course I use activiti-rest API to integrate the BPM product in our frontend product.