cancel
Showing results for 
Search instead for 
Did you mean: 

CandidateUsers from java code in BPMN

kgiannakakis
Champ in-the-making
Champ in-the-making
I'd like to call java code to populate the candidate users in a user task. Something like this:

<php>
<userTask id="MyUserTask" name="User Actions" activiti:candidateUsers="${candidateUsers.getAllCandidateUsers()}">
</php>

where
candidateUsers
is a Spring bean. Is this possible? What are the requirements for the Spring bean?

I know that I can have a Service Task in front of the User Task and use a variable, but the above syntax would make the bpmn smaller.
9 REPLIES 9

jbarrez
Star Contributor
Star Contributor
Yes, that is possible. If you are using the Spring integration, this works out of the box. If not, then you must set those beans manually by calling the setBeans() of the process engine configuration.

kgiannakakis
Champ in-the-making
Champ in-the-making
Well, I've actually tried this with a Spring Bean, but couldn't get it to work. I created the method getAllCandidateUsers, and have it return a String array of names. I know it is being called, because of a print out, I've inserted. However, I then got an exception about the expression not being able to evaluated as a string or a collection. What should my method return?

muralidharand
Star Contributor
Star Contributor
Try to return as <java>List<String></java> instead of returning them as Array of string.
In my case, I have used the below one.
<java>activiti:candidateUsers="${clientManagers}"</java>
I have created clientManagers variable in the java delegate as <java>List<String> clientManagers</java>

kgiannakakis
Champ in-the-making
Champ in-the-making
Thanks Murali, your answer helped. It was indeed necessary to use <code>List<String></code> instead of <code>String []</code>.

I can now start the process, but I have a different kind of problem. The task isn't visible to anyone. In the ACT_RU_IDENTITYLINK table, I can see "kermit,fozzie,gonzo" as USER_ID_. There is only one single entry generated.

This is my addition is spring context:

<code>
<bean id="candidateUsers" class="mypackage.CandidateUsers" />
</code>

This is my Java code:

<java>
public class CandidateUsers {

public List<String> getAllCandidateUsers() {
  String [] users = {"kermit,fozzie,gonzo"};
  return Arrays.asList(users);
}
}
</java>

and this is my process:

<code>
    <userTask id="TopUserActionUserTask" name="Top User Actions" activiti:candidateUsers="${candidateUsers.getAllCandidateUsers()}">
</code>

jbarrez
Star Contributor
Star Contributor
That's because you do only return one string … {"kermit,fozzie,gonzo"};

It should be {"kermit","fozzie","gonzo"};

kgiannakakis
Champ in-the-making
Champ in-the-making
You are right that I need to return only a single string. However, the proposed format didn't work. This is what it finally had it working:

<java>
public String getAllCandidateUsers() {
return "kermit, fozzie, gonzo";
}
</java>

That is a single comma separated list, without quotes and curly braces. Thanks for the help.

jbarrez
Star Contributor
Star Contributor
That's why I commented to use separate strings instead of one 😉

kgiannakakis
Champ in-the-making
Champ in-the-making
You are of course right. This:

<java>
public List<String> getAllCandidateUsers() {
String [] users = {"kermit","fozzie","gonzo"};
return Arrays.asList(users);
}
</java>

also works. I misinterpreted your answer, because I actually thought the missing quotes were there.

timsim
Champ in-the-making
Champ in-the-making
I am a beginner, and I want to get deep understanding about the uses of jBPM, the amazing open-source workflow engine written in Java that’s especially useful for business related activities. Now, that I have joined a prestigious <a href="http://www.java-forums.org/forum.php">Java forum</a>, I am sure that I will be able to learn many things under a single roof.