cancel
Showing results for 
Search instead for 
Did you mean: 

Enum defaults are not filled in form

activista
Champ in-the-making
Champ in-the-making
Hello Activity Forum,

I am just wondering if this is with purpose, but with form properties for the enum type default value are not automatically filled.
If not purposeful, can this be corrected?

Regards,
A.
8 REPLIES 8

jbarrez
Star Contributor
Star Contributor
Can you give an example of that? It's a long time ago since we wrote those enum form properties 😉

udoderk
Champ in-the-making
Champ in-the-making
Can you give an example of that? It's a long time ago since we wrote those enum form properties 😉
i have example Smiley Wink - Vacation request

[img]http://img94.imageshack.us/img94/1870/activitiemptydeflz.png[/img]

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" id="definitions" targetNamespace="http://activiti.org/bpmn20">
<process id="vacationRequest" name="Vacation request">
<startEvent id="request" activiti:initiator="employeeName">
<extensionElements>
<activiti:formProperty id="numberOfDays" name="Number of days" type="long" value="1" required="true"/>
<activiti:formProperty id="startDate" name="First day of holiday (dd-MM-yyy)" datePattern="dd-MM-yyyy hh:mm" type="date" required="true"/>
<activiti:formProperty id="vacationMotivation" name="Motivation" type="string"/>
</extensionElements>
</startEvent>
<sequenceFlow id="flow1" sourceRef="request" targetRef="handleRequest"/>
<userTask id="handleRequest" name="Handle vacation request">
<documentation>
${employeeName} would like to take ${numberOfDays} day(s) of vacation (Motivation: ${vacationMotivation}).
</documentation>
<extensionElements>
<activiti:formProperty id="vacationApproved" name="Do you approve this vacation" type="enum" required="true">
<activiti:value id="true" name="Approve"/>
<activiti:value id="false" name="Reject"/>
</activiti:formProperty>
<activiti:formProperty id="managerMotivation" name="Motivation" type="string"/>
</extensionElements>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>management</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<sequenceFlow id="flow2" sourceRef="handleRequest" targetRef="requestApprovedDecision"/>
<exclusiveGateway id="requestApprovedDecision" name="Request approved?"/>
<sequenceFlow id="flow3" sourceRef="requestApprovedDecision" targetRef="sendApprovalMail">
<conditionExpression xsi:type="tFormalExpression">${vacationApproved == 'true'}</conditionExpression>
</sequenceFlow>
<task id="sendApprovalMail" name="Send confirmation e-mail"/>
<sequenceFlow id="flow4" sourceRef="sendApprovalMail" targetRef="theEnd1"/>
<endEvent id="theEnd1"/>
<sequenceFlow id="flow5" sourceRef="requestApprovedDecision" targetRef="adjustVacationRequestTask">
<conditionExpression xsi:type="tFormalExpression">${vacationApproved == 'false'}</conditionExpression>
</sequenceFlow>
<userTask id="adjustVacationRequestTask" name="Adjust vacation request">
<documentation>
Your manager has disapproved your vacation request for ${numberOfDays} days. Reason: ${managerMotivation}
</documentation>
<extensionElements>
<activiti:formProperty id="numberOfDays" name="Number of days" value="${numberOfDays}" type="long" required="true"/>
<activiti:formProperty id="startDate" name="First day of holiday (dd-MM-yyy)" value="${startDate}" datePattern="dd-MM-yyyy hh:mm" type="date" required="true"/>
<activiti:formProperty id="vacationMotivation" name="Motivation" value="${vacationMotivation}" type="string"/>
<activiti:formProperty id="resendRequest" name="Resend vacation request to manager?" type="enum" required="true">
<activiti:value id="true" name="Yes"/>
<activiti:value id="false" name="No"/>
</activiti:formProperty>
</extensionElements>
<humanPerformer>
<resourceAssignmentExpression>
<formalExpression>${employeeName}</formalExpression>
</resourceAssignmentExpression>
</humanPerformer>
</userTask>
<sequenceFlow id="flow6" sourceRef="adjustVacationRequestTask" targetRef="resendRequestDecision"/>
<exclusiveGateway id="resendRequestDecision" name="Resend request?"/>
<sequenceFlow id="flow7" sourceRef="resendRequestDecision" targetRef="handleRequest">
<conditionExpression xsi:type="tFormalExpression">${resendRequest == 'true'}</conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow8" sourceRef="resendRequestDecision" targetRef="theEnd2">
<conditionExpression xsi:type="tFormalExpression">${resendRequest == 'false'}</conditionExpression>
</sequenceFlow>
<endEvent id="theEnd2"/>
</process>
</definitions>

udoderk
Champ in-the-making
Champ in-the-making
Hello Activity Forum,

I am just wondering if this is with purpose, but with form properties for the enum type default value are not automatically filled.
If not purposeful, can this be corrected?

Regards,
A.

How you define the default value for enum in bpmn20.xml file?

activista
Champ in-the-making
Champ in-the-making
This is how it is done as the result of the Eclipse Designer; refer to line activiti:formProperty id="examtype":


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="process1" name="process1">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="Exam selection" activiti:assignee="kermit">
      <extensionElements>
        <activiti:formProperty id="examtype" name="Exam type" type="enum" default="h">
          <activiti:value id="m" name="Maths"></activiti:value>
          <activiti:value id="l" name="Literature"></activiti:value>
          <activiti:value id="h" name="History"></activiti:value>
        </activiti:formProperty>
      </extensionElements>
    </userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_process1">
    <bpmndi:BPMNPlane bpmnElement="process1" id="BPMNPlane_process1">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="110" y="150"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55" width="105" x="220" y="140"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="420" y="150"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="145" y="167"></omgdi:waypoint>
        <omgdi:waypoint x="220" y="167"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="325" y="167"></omgdi:waypoint>
        <omgdi:waypoint x="420" y="167"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

udoderk
Champ in-the-making
Champ in-the-making
This is how it is done as the result of the Eclipse Designer; refer to line activiti:formProperty id="examtype":
….
      <extensionElements>
        <activiti:formProperty id="examtype" name="Exam type" type="enum" default="h">
          <activiti:value id="m" name="Maths"></activiti:value>
          <activiti:value id="l" name="Literature"></activiti:value>
          <activiti:value id="h" name="History"></activiti:value>
        </activiti:formProperty>
      </extensionElements>
    </userTask>

The default="h" value is just ignored intoorg.activiti.explorer.ui.form.EnumFormPropertyRenderer of A.E: 5.10 and A.E 5.11  :geek:
public class EnumFormPropertyRenderer extends AbstractFormPropertyRenderer {

  public EnumFormPropertyRenderer() {
    super(EnumFormType.class);
  }

  @SuppressWarnings("unchecked")
  @Override
  public Field getPropertyField(FormProperty formProperty) {
    ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
    comboBox.setRequired(formProperty.isRequired());
    comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
    comboBox.setEnabled(formProperty.isWritable());

    Map<String, String> values = (Map<String, String>) formProperty.getType().getInformation("values");
    if (values != null) {
      for (Entry<String, String> enumEntry : values.entrySet()) {
        // Add value and label (if any)
        comboBox.addItem(enumEntry.getKey());
        if (enumEntry.getValue() != null) {
          comboBox.setItemCaption(enumEntry.getKey(), enumEntry.getValue());
        }
      }
    }
    return comboBox;
  }
}

The org.activiti.engine.form.FormProperty interface has no method, that would be represent the "default" attribute of xml element formProperty :roll:

jbarrez
Star Contributor
Star Contributor
So what you're saying is that there is a bug in that impl, right? Please create a jira issue so we can follow it up (and link it to this post)

houstoniasian
Champ in-the-making
Champ in-the-making
As of today 09/27/2013, this is still an issue.  I'm using 5.13.

/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.activiti.explorer.ui.form;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.activiti.engine.form.FormProperty;
import org.activiti.engine.impl.form.EnumFormType;
import org.activiti.explorer.Messages;

import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Field;

/**
* @author Frederik Heremans
* @author Joram Barrez
*/
public class EnumFormPropertyRenderer extends AbstractFormPropertyRenderer {

  public EnumFormPropertyRenderer() {
    super(EnumFormType.class);
  }

  @SuppressWarnings("unchecked")
  @Override
  public Field getPropertyField(FormProperty formProperty) {

   System.out.println("formProperty.getId() " + formProperty.getId());
   System.out.println("formProperty.getName() " + formProperty.getName());
   System.out.println("formProperty.getValue() " + formProperty.getValue()); 
  
    ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
    comboBox.setRequired(formProperty.isRequired());
    comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
    comboBox.setEnabled(formProperty.isWritable());
    comboBox.setNullSelectionAllowed(false);

    Object firstItemId = null;
    Map<String, String> values = (Map<String, String>) formProperty.getType().getInformation("values");
  
    Iterator it = values.entrySet().iterator();
    while (it.hasNext()){
   System.out.println(it.next());
    }
   
    if (values != null) {
      for (Entry<String, String> enumEntry : values.entrySet()) {
        // Add value and label (if any)
        comboBox.addItem(enumEntry.getKey());
       
        if (firstItemId == null) {
          firstItemId = enumEntry.getKey(); // select first element
          System.out.println("firstItemId" + firstItemId);
        }
       
        if (enumEntry.getValue() != null) {
          comboBox.setItemCaption(enumEntry.getKey(), enumEntry.getValue());
          System.out.println(" enumEntry.getValue()" +  enumEntry.getValue());
        }
      }
    }
   
    // Select first element
    if (firstItemId != null) {
      <b>comboBox.select(formProperty.getValue());</b>
    }
   
    return comboBox;
  }
}