Cam-choices with expression camunda:formField defaultValue

Hello,

I tried to use form fileds to provide values to the start form with defaultValue in combination with an CDI bean expression in order to compute the value there.

 <bpmn:startEvent id="Event_1v2yq2n" name="initier demande" camunda:formKey="embedded:app:forms/start-demande.html" camunda:initiator="initiator">
      <bpmn:extensionElements>
        <camunda:formData>
          <camunda:formField id="structures" type="string" defaultValue="${structureGestionService.getStructures()}">
          </camunda:formField>
        </camunda:formData>
      </bpmn:extensionElements>
      <bpmn:outgoing>Flow_0ug0v28</bpmn:outgoing>
    </bpmn:startEvent>

Here the java code :

@ManagedBean
public class StructureGestionService {

    public Map<String,String> getStructures() {

        Map<String, String> structures = new HashMap<String, String>();
        structures.put("001", "DRH");
        structures.put("002", "DKO");
        structures.put("003", "DDD");

        return structures;
    }
}

And then in embedded html form:

 <!-- Structure accueil -->
            <div class="form-group">
                <label for="structureAccueil">Structure accueil</label>
                <div class="controls">
                    <!--select box -->
                    <select class="form-control"
                            cam-variable-name="structure"
                            cam-variable-type="String"
                            cam-choices=structures>
                    </select>
                </div>
            </div> 

The problem is that the select box is rendered like this:

Can anybody have a solution?

image

Please, i tried everything SPIN.JSON, serializationDataFormat… As it’s the start form, I can’t use setVariable of process engine…

Your most straightforward solution is to maintain your options in the form itself

<select id="structureAccueil"
              class="form-control"
              cam-variable-name="structure"
              cam-variable-type="String">
        <option value="001">DRH</option>
        <option value="002">DKO</option>
        <option value="003">DDD</option>
      </select>

But I’m guessing you’re ultimately looking for something more dynamic. As you indicated, I think your options are pretty limited, given the nature of the start form. The only option I can think of is to load the data via a REST call back to the server, similar to what is described in this thread. Keeping that data as a resource in the deployment seems a little heavy-handed, but you could maintain your own API for something more lightweight.

1 Like