cancel
Showing results for 
Search instead for 
Did you mean: 

Help understanding @BusinessProcessScoped beans

pkonyves
Champ in-the-making
Champ in-the-making
I came across the @BusinessProcessScoped bean section in the activiti online documentation, but I don't know how I or Actviti knows which BusinessProcessScoped bean to inject.

I assume if I create such a bean with the @Named annotation, I can reference it from the process definition. Then Activiti will know which BusinessProcessScoped bean belongs to which process instance.

However what if I want to @Inject this bean into other CDI beans e.g. a @RequestScope bean in  a JSF application. e.g.:


@BusinessProcessScoped
public class MyProcessBean implements java.io.Serializable {
  // this bean persists its state throughout the whole process instance
  private String lastChangingUser;

  //getters&setters
}

@RequestScoped
public class MyTaskController {

  @Inject MyProcessBean myProcessBean;

  public void updateLastChangingUser() {
   Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
   myProcessBean.setLastChangingUser( principal.getName() );
  }
}

How will Activiti know, how can I tell it for which process instance it should inject the MyProcessBean?
Thanks, Pal
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
You don't: it works the other way around, as the scope only matters when you're talking about the lifecycle of this bean. The bean will only be the same during the duration of the process instance.

From the docs: 'Sometimes, we want to work with process scoped beans, in the absence of an association with a process instance, for example before starting a process. If no process instance is currently active, instances of BusinessProcessScoped beans are temporarily stored in a local scope (I.e. the Conversation or the Request, depending on the context. If this scope is later associated with a business process instance, the bean instances are flushed to the process instance.'