Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use ArrayList in Data? #15

Open
masa2146 opened this issue Mar 1, 2021 · 0 comments
Open

Can I use ArrayList in Data? #15

masa2146 opened this issue Mar 1, 2021 · 0 comments

Comments

@masa2146
Copy link

masa2146 commented Mar 1, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant