Find file History
koevskinikola chore(release): adjust examples for 7.10 release
* Adjust Deployment examples for 7.10 release
* Adjust Spring Boot examples for 7.10 release
* Bump plain spring boot to 2.0.2
* Adjust Plugin & Model API examples for 7.10 release
* Adjust & migrate Webapps examples for 7.10 release
* Adjust BPMN 2.0 examples for 7.10 release
* Adjust misc examples for 7.10 release
* Add null check for Process Migration example, so that it works for WildFly distros
* Set compiler source and target to jdk 1.7 and remove support for JDK6
* Add missing license headers to java source files;
* Format existing license headers in java files to get a
consitent pattern.

Related to CAM-9524, CAM-9481, CAM-9477, CAM-9480, CAM-9478, CAM-9482,
CAM-9479, CAM-9545, CAM-9537
Latest commit 94138be Nov 20, 2018
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src/main chore(release): adjust examples for 7.10 release Nov 30, 2018
README.md fix(translation): correct english translation for user labels Nov 5, 2018
pom.xml chore(release): adjust examples for 7.10 release Nov 30, 2018

README.md

Serialized Objects in Embedded Forms

This example demonstrates how to work with serialized Java objects in embedded forms.

The BPMN Process used in this example

Create customer rating process

The process is kicked off by a form where the user is supposed to provide data about a customer. The process then attempts to calculate a rating using a Java Class. If the rating cannot be calculated automatically, a usertask is created and the user has to calculate the rating manually.

Modeling data as Java Objects

Customer data is modeled using a Java Class:

public class CustomerData {

  protected String firstname;
  protected String lastname;
  protected boolean isVip;
  protected float rating;
  protected List<Address> addresses = new ArrayList<Address>();

  // ... getters / setters omitted
}

The CustomerData class provides a collection of addresses. Addresses are modeled like this:

public class Address {

  protected String street;
  protected String zipCode;
  protected String city;
  protected String country;

  // ... getters / setters omitted
}

Creating a Java Object Variable in a Start Form

The process instance is started using a form. The form is a plain HTML form which is displayed inside Camunda Tasklist (or inside a custom application using the camunda-bpm-sdk-js library).

<form name="customerForm" role="form">

  <script cam-script type="text/form-script">

    // angular form works on scope object
    var customerData = $scope.customerData = {
      addresses : []
    };

    // hook into camunda SDK JS Form Lifecycle
    camForm.on('form-loaded', function() {

      // declare variable 'customerData' incuding metadata for serialization
      camForm.variableManager.createVariable({
        name: 'customerData',
        type: 'Object',
        value: customerData,
        valueInfo: {
          // indicate that object is serialized as json
          serializationDataFormat: 'application/json',
          // provide classname of java object
          objectTypeName: 'org.camunda.bpm.example.usertask.embedded.serialized.model.CustomerData'
        }
      });

    });

  </script>

  <h3>Customer Data</h3>

  <div class="control-group">
    <label class="control-label" for="firstname">First Name</label>
    <div class="controls">
      <input id="firstname"
             class="form-control"
             type="text"
             required 
             ng-model="customerData.firstname">
    </div>

  <!-- ... Additional fields ommitted -->

  </div>
</form>

The custom java script creates a Javascript Object and binds it to the angular $scope of the form as a variable named customerData. We then hook into the lifecycle of camunda SDK JS Form and create a process variable named customerData and provide additional type information and metadata used for serialization. The Object should be serialized as "application/json" and the type of the object is org.camunda.bpm.example.usertask.embedded.serialized.model.CustomerData.

The form itself is a plain angular js form (see ng-model binding of input field).

Accessing the Object Variable

In a Java Delegate, the customerData variable can be retrieved in the regular way:

public class CalculateRating implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {

    CustomerData customerData = (CustomerData) execution.getVariable("customerData");

    // ...
  }
}

Accessing an existing Java Object Variable in a Task Form

In a task form, an existing Java Object variable can be accessed using custom Javascript. The pattern is to first fetch the value of the variable and then bind it to an angular scope variable:

camForm.on('form-loaded', function() {
  // fetch the variable named 'customerData'
  camForm.variableManager.fetchVariable('customerData');
});

camForm.on('variables-fetched', function() {
  // after the variables are fetched, bind the value of customerData to a angular
  // scope value such that the form can work on it
  $scope.customerData = camForm.variableManager.variable('customerData').value;
});

Running the example

  1. Download a Camunda BPM Distribution
  2. Checkout this repository using Git
  3. Build the example using mvn clean package
  4. Deploy the .war file located in the target/ folder to the server
  5. Open Camunda Tasklist using the URL http://localhost:8080/camunda/app/tasklist
  6. Start a new instance of the Process.