01-09-2013 08:04 AM
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]
}
}
01-10-2013 02:56 AM
01-11-2013 04:42 AM
How does your BPMN20.xml look like? Maybe you wired the service-task JavaDelegate in a wring way (e.g.? using activiti:class). If the JavaDelegate is not retrieved from the CDI-context, it makes sense that the @Injects are not working…
<process id="incident" name="Incident Demo" isExecutable="true">
<startEvent id="startevent1" name="Start" activiti:formKey="create.xhtml"></startEvent>
<userTask id="usertask1" name="Update Incident" activiti:assignee="${manager}" activiti:formKey="update.xhtml"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<serviceTask id="servicetask1" name="Save Incident" activiti:class="com.rolta.onv.im.server.IncidentSaveService"></serviceTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
</process>
01-11-2013 04:59 AM
01-13-2013 02:52 AM
I see you're using activiti:class="com.rolta.onv.im.server.IncidentSaveService" (As I suspected in my previous post). When you use this, activiti will just instantiate an instance of the given class, without any "special" treatment at all. So the constructor will just be called. All the @Injects won't work because the instance is not retrieved from the CDI-context.
You'll have to use activiti:delegateExpression="${incidentSaveService}" instead, combined with a CdiJtaProcessEngineConfiguration (which has a CdiResolver inside, capable of resolving CDI-beans in expressions used in activiti). This will enable you to use the CDI-bean named "incidentSaveService" in activiti.
08-23-2016 07:59 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.