cancel
Showing results for 
Search instead for 
Did you mean: 

How to get ProcessInstance from BusinessProcess.

sherlock
Champ in-the-making
Champ in-the-making
Hi,
I have taken ui-mediator example from below link.

http://www.bpm-guide.de/2012/04/04/pageflow-vs-process-flow-and-ui-mediator-pattern/

While creating the the ProcessInstance through BusinessProcess i am getting NullPointerException.

My code is like Below.


package com.rolta.onv.ui.customerregistration;

import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.activiti.cdi.BusinessProcess;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.log4j.Logger;

import com.rolta.onv.ui.util.CustomerUtil;


@ManagedBean(name="customerService")
@RequestScoped
public class CustomerService {
   
    private static Logger sLog = Logger.getLogger(CustomerService.class.getName());
    public static final String VARNAME_CUSTOMER_ID = "customerId";
    public static final String PROCESS_KEY = "uimediator";
   
    private static EntityManagerFactory factory =  Persistence.createEntityManagerFactory("Worksample");
EntityManager entityManager= factory.createEntityManager();
  private BusinessProcess businessProcess;

    private CustomerEO customer;
   
    @ManagedProperty(value="#{customerUtil}")
    private CustomerUtil customerUtil;
    public CustomerEO getCustomer()
    {
       if(customer==null)
       {
          Long customerId = businessProcess.getVariable(VARNAME_CUSTOMER_ID);
             customer = entityManager.find(CustomerEO.class, customerId);
       }
       return customer;
    }
   
    public CustomerEO getNewOrder() {
        if (customer == null) {
          customer = new CustomerEO();
        }
        return customer;
      }
       
    public CustomerService() {
   
   }
    public CustomerUtil getCustomerUtil() {
      return customerUtil;
   }
   public void setCustomerUtil(CustomerUtil customerUtil) {
      this.customerUtil = customerUtil;
   }
    public ProcessInstance startCustomerRegistration() {
        if (customer == null) {
             customer = new CustomerEO();
           }
       
       entityManager.getTransaction().begin();
       customer.setFirstname(customerUtil.getUserName());
       customer.setLastname(customerUtil.getLastName());
       entityManager.persist(customer);
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put(VARNAME_CUSTOMER_ID, customer.getId());
        this.customer = null;
        entityManager.getTransaction().commit();
       System.out.println("variables—————"+variables);
   
       return businessProcess.startProcessByKey(PROCESS_KEY, variables);
      }
}




Please tell me how to ProcessInstance from BusinessProcess.
1 REPLY 1

p4w3l
Champ in-the-making
Champ in-the-making
I am not sure but maybe try: @Inject private BusinessProcess businessProcess; But you must use Activiti CDI first in your configuration. See manual.