Java Service Task Problem with List

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2011 09:06 AM
Hello,
i want to set List of users (productmanagers) as a variable. I want to reuse this variable for a multiinstance task which needs a collection. The collection should contain these users. I tried different possibilities but only get Exception:couldn't instantiate class. Does anybody know how to store a list as a process variable so i can use it as a collection in a multi-instance task?
Thank for your help!
public class IdentifyMembers implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("SERVICE");
String[] str_memberList = {"geschaeftsfuehrer", "controller", "hbl_it", "hbl_2", "prod_man_1", "prod_man_2", "auftraggeber_1"};
String[] str_productmanagerList = {"prod_man_1", "prod_man_2"};
List<String> productmanagerList = Arrays.asList(str_productmanagerList);
//first try
execution.setVariable("productmanagerList", CollectionUtil.singletonMap("productmanagerList", productmanagerList));
//second try
//Map<String, Object> map = new HashMap<String, Object>();
//map.put("productmanagerList", productmanagerList);
//execution.setVariable("productmanagerList", map);
}
}
i want to set List of users (productmanagers) as a variable. I want to reuse this variable for a multiinstance task which needs a collection. The collection should contain these users. I tried different possibilities but only get Exception:couldn't instantiate class. Does anybody know how to store a list as a process variable so i can use it as a collection in a multi-instance task?
Thank for your help!
public class IdentifyMembers implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("SERVICE");
String[] str_memberList = {"geschaeftsfuehrer", "controller", "hbl_it", "hbl_2", "prod_man_1", "prod_man_2", "auftraggeber_1"};
String[] str_productmanagerList = {"prod_man_1", "prod_man_2"};
List<String> productmanagerList = Arrays.asList(str_productmanagerList);
//first try
execution.setVariable("productmanagerList", CollectionUtil.singletonMap("productmanagerList", productmanagerList));
//second try
//Map<String, Object> map = new HashMap<String, Object>();
//map.put("productmanagerList", productmanagerList);
//execution.setVariable("productmanagerList", map);
}
}
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2011 09:40 AM
I think, List is only an interface and thus can't be instantiated. Use ArrayList or something instead.
regards
regards

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2011 09:55 AM
I did this before and it works to store my list:
public class MyJavaService implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("SERVICE");
String[] str_assigneeList = {"kermit", "gonzo", "fozzie"};
execution.setVariable("assigneeList", str_assigneeList);
}
}
But the problem is that i cannot use this "assigneeList" as a collection in the multi-instance task. Thats the main issue. The following example works when i start a new process instance and i can use the "assigneeList" in my multi-instance task. But i want so set the variables in Java ServiceTask.
String[] str_assigneeList = {"kermit", "gonzo", "fozzie"};
List<String> assigneeList = Arrays.asList(str_assigneeList);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MultiInstanceTask", CollectionUtil.singletonMap("assigneeList", assigneeList));
System.out.println("Started Process instance id " +processInstance.getProcessInstanceId());
public class MyJavaService implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {
System.out.println("SERVICE");
String[] str_assigneeList = {"kermit", "gonzo", "fozzie"};
execution.setVariable("assigneeList", str_assigneeList);
}
}
But the problem is that i cannot use this "assigneeList" as a collection in the multi-instance task. Thats the main issue. The following example works when i start a new process instance and i can use the "assigneeList" in my multi-instance task. But i want so set the variables in Java ServiceTask.
String[] str_assigneeList = {"kermit", "gonzo", "fozzie"};
List<String> assigneeList = Arrays.asList(str_assigneeList);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MultiInstanceTask", CollectionUtil.singletonMap("assigneeList", assigneeList));
System.out.println("Started Process instance id " +processInstance.getProcessInstanceId());

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2011 11:17 AM
String[] str_productmanagerList = {"prod_man_1", "prod_man_2"};
Collection<String> productmanagerList = Arrays.asList(str_productmanagerList);
execution.setVariable("productmanagerList", productmanagerList);
I finally got it. It works with Collection.
Collection<String> productmanagerList = Arrays.asList(str_productmanagerList);
execution.setVariable("productmanagerList", productmanagerList);
I finally got it. It works with Collection.
