Hi,I want to store process variables into database after completion of the process.I'm new to CDI so not able to store the variable values in database.Can anybody please help me….my code is as following
public interface UserDao {
void saveIncident(String incidentID,long number,String title,String locDesc,String cause,String actionTaken,String injuries,String fatalities,String assignor,Date incidentDate,String actFlag);
}
@SessionScoped
public class ManagedBeanUserDao implements UserDao,Serializable {
private static final long serialVersionUID = 1L;
@Inject
private EntityManager entityManager;
@Inject
private UserTransaction utx;
@Override
public void saveIncident(String incidentID, long number, String title,
String locDesc, String cause, String actionTaken, String injuries,
String fatalities, String assignor, Date incidentDate,String actFlag) {
// TODO Auto-generated method stub
try {
try {
[b] [color=#4000FF] utx.begin();[/color][/b]
try {
IncdtMstrEO mstrEO=new IncdtMstrEO();
mstrEO.setIncdtId(incidentID);
mstrEO.setIncdtNum(number);
mstrEO.setIncdtTitle(title);
mstrEO.setLocDesc(locDesc);
mstrEO.setCause(cause);
mstrEO.setActTaken(actionTaken);
mstrEO.setInjur(injuries);
mstrEO.setFatal(fatalities);
mstrEO.setOwner(assignor);
mstrEO.setCrtDate(incidentDate);
mstrEO.setActFlag("Y");
entityManager.persist(mstrEO);
} catch (NoResultException e) {
System.out.println(e);
}
} finally {
utx.commit();
}
} catch (Exception e) {
try {
[b] [color=#4040FF] utx.rollback();[/color][/b]
} catch (SystemException se) {
throw new RuntimeException(se);
}
throw new RuntimeException(e);
}
}
}
@Named
@SessionScoped
public class GreetController implements Serializable{
@Inject
private UserDao userDao;
public void saveIncident(String incidentID,long number,String title,String locDesc,String cause,String actionTaken,String injuries,String fatalities,String assignor,Date incidentDate,String actFlag)
{
System.out.println("UserDao Object————–"+userDao);
userDao.saveIncident(incidentID, number, title, locDesc, cause, actionTaken, injuries, fatalities, assignor,incidentDate, actFlag);
}
}
@SessionScoped
public class IncidentSaveService implements JavaDelegate,Serializable {
private static final long serialVersionUID = 1L;
@Inject
GreetController controller;
@Override
public void execute(DelegateExecution execute) throws Exception {
System.out.println("Incident Id——–"+execute.getProcessInstanceId());
System.out.println("incident date————"+(Date)execute.getVariable("incidentDate"));
System.out.println("Incident Number——-"+execute.getVariable("incidentNumber"));
System.out.println("incident title———"+execute.getVariable("incidentTitle"));
System.out.println("incident location description—-"+execute.getVariable("locDesc"));
System.out.println("cause—————-"+execute.getVariable("cause"));
System.out.println("action taken———–"+execute.getVariable("actionTaken"));
System.out.println("injuries———"+execute.getVariable("injuries"));
System.out.println("fatalities———"+execute.getVariable("fatalities"));
System.out.println("assignor————-"+execute.getVariable("assignor").toString());
System.out.println("Approve————-"+execute.getVariable("approve").toString());
String incidentID=(String)execute.getProcessInstanceId();
long incidentNumber=(new Long(execute.getVariable("incidentNumber").toString()).longValue());
String title=execute.getVariable("incidentTitle").toString();
String locDesc=execute.getVariable("locDesc").toString();
String cause=execute.getVariable("cause").toString();
String actTaken=execute.getVariable("actionTaken").toString();
String injuries=execute.getVariable("injuries").toString();
String fatal=execute.getVariable("fatalities").toString();
String owner=execute.getVariable("assignor").toString();
String actFlag=(execute.getVariable("approve").toString()=="true"?"Y":"N");
System.out.println(owner);
System.out.println("UserDao——————"+userDao);
[b][color=#FF0000]controller.saveIncident(incidentID, incidentNumber, title, locDesc, cause, actTaken, injuries, fatal, owner, new Date(), actFlag);[/color][/b]
}
}
Here the controller object in the IncidentSaveService i'm getting as null.Event if i create it as new object i'm getting error at the code specified in the blue. please help me.