jworkflow icon indicating copy to clipboard operation
jworkflow copied to clipboard

Can I use ArrayList in Data?

Open masa2146 opened this issue 3 years ago • 0 comments

Hello, I want to show each data in ArrayList with foreach loop with using json file. This is my json file

{
  "id": "test-workflow",
  "version": 1,
  "dataType": "io.blt.MyData",
  "steps": [
    {
      "id": "step1",
      "stepType": "io.steps.Hello",
      "nextStepId": "step2"
    },
    {
      "id": "step2",
      "stepType": "net.jworkflow.primitives.Foreach",
      "nextStepId": "step3",
      "inputs": {
        "collection": "data.values.toArray(new Object[0])"
      },
      "thenDo": [
        [
          {
            "id": "step2.1",
            "stepType": "io.steps.PrintMessage",
            "inputs": {
              "message": "'doing 2.1' + data.values.toArray(new Object[0])[step.index]"
            }
          }
        ]
      ]
    },
    {
      "id": "step3",
      "stepType": "io.steps.Goodbye"
    }
  ]
}

MyData class is

public class MyData {
    public int value1;
    public int value2;
    public int value3;
    public List<Object> values = new ArrayList<>();
    public Object[] collection1;
}

and PrintMessage class is


public class PrintMessage implements StepBody {

    public String message;
    public int index;

    @Override
    public ExecutionResult run(StepExecutionContext context) {
        System.out.println(message);
        index++;
        return ExecutionResult.next();
    }
}

Error:

 java.lang.RuntimeException: javax.script.ScriptException: TypeError: Object[0] is not a function in <eval> at line number 1

when I use primitive array instade of ArrayList then It works. But I want to use ArrayList. Can I use? One more thing, Can I get each value of the array without declare extra index in PrintMessage class.

masa2146 avatar Mar 01 '21 15:03 masa2146