cancel
Showing results for 
Search instead for 
Did you mean: 

How to create the activiti expressions and listeners

valarmathi
Champ in-the-making
Champ in-the-making
Hi,
How can i use the activiti expressions(java script expressions) and listeners.
Please tell me the flow how can i do it?

Thanks,
Valarmathi P
27 REPLIES 27

jbarrez
Star Contributor
Star Contributor
See http://activiti.org/userguide/index.html#executionListeners

Replace the 'class' with expression if you only need expressions.


In Activiti 5.11 (not yet released), it will be possible to use script tasks, like


<userTask id="usertask1" name="All your base are belong to us">
   <extensionElements>
    <activiti:taskListener event="create" class="org.activiti.engine.impl.bpmn.listener.ScriptTaskListener">
     <activiti:field name="script">
      <activiti:string>
                def bar = "BAR";  // local variable
                foo = "FOO"; // pushes variable to execution context
                bar // implicit return value
               </activiti:string>
     </activiti:field>
     <activiti:field name="language" stringValue="groovy" />
     <activiti:field name="resultVariable" stringValue="myVar" />
    </activiti:taskListener>
   </extensionElements>
  </userTask>
 

valarmathi
Champ in-the-making
Champ in-the-making
I used 5.10 ,what i have to do.I don't know how to use the expressions and listeners .Please help me if anybody knowa.

Thanks ,
Valarmathi P

jbarrez
Star Contributor
Star Contributor
Please check the docs I linked to:

eg



    <userTask id="firstTask" />
    <sequenceFlow sourceRef="firstTask" targetRef="secondTask">
    <extensionElements>
      <activiti:executionListener class="org.activiti.examples.bpmn.executionListener.ExampleExecutionListenerTwo" />
    </extensionElements>
    </sequenceFlow>
   

valarmathi
Champ in-the-making
Champ in-the-making
Hi,

I used three usertask executionListeners ,

I got the following error.

Exception

com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: couldn't instantiate class org.activiti.examples.bpmn.executionlistener.ExampleExecutionListenerOne
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1193)
at com.vaadin.ui.Button.fireClick(Button.java:539)
at com.vaadin.ui.Button.changeVariables(Button.java:206)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1299)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1219)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:735)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.activiti.engine.ActivitiException: couldn't instantiate class org.activiti.examples.bpmn.executionlistener.ExampleExecutionListenerOne
at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:131)
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.instantiateDelegate(ClassDelegate.java:162)
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.getExecutionListenerInstance(ClassDelegate.java:76)
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:68)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:42)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:80)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:546)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:541)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.start(ExecutionEntity.java:335)
at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:72)
at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute(StartProcessInstanceCmd.java:31)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceById(RuntimeServiceImpl.java:63)
at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceById(RuntimeServiceImpl.java:63)
at org.activiti.explorer.ui.process.listener.StartProcessInstanceClickListener.buttonClick(StartProcessInstanceClickListener.java:71)
at sun.reflect.GeneratedMethodAccessor99.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:490)
… 22 more
Caused by: org.activiti.engine.ActivitiClassLoadingException: Class not found: org.activiti.examples.bpmn.executionlistener.ExampleExecutionListenerOne
at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:81)
at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:128)
… 44 more
Caused by: java.lang.ClassNotFoundException: org.activiti.examples.bpmn.executionlistener.ExampleExecutionListenerOne
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:62)
… 45 more

Thanks,

Valarmathi P

frederikherema1
Star Contributor
Star Contributor
Make sure the classes you reference are in your class path of the activiti-explorer WAR…

valarmathi
Champ in-the-making
Champ in-the-making
I checked the class its there in my war file.but i'm getting the same error.
Please help me

Thanks,
Valarmathi P

frederikherema1
Star Contributor
Star Contributor

Caused by: java.lang.ClassNotFoundException: org.activiti.examples.bpmn.executionlistener.ExampleExecutionListenerOne

I think you should double-check if the class is rather in WEB-INF/classes or in a jar-file in the lib-folder…

valarmathi
Champ in-the-making
Champ in-the-making
I created Activity project only,so the class should be there in .bar file only.I tested in jUnit its running ,but Activity explorer showing the error.

Thanks,
Valarmathi P

frederikherema1
Star Contributor
Star Contributor
Userguide states:

Note that Java classes present in the business archive will not be added to the classpath. All custom classes used in process definitions in the business archive (for example Java service tasks or event listener implementations) should be present on the activiti-engine's classpath in order to run the processes.

The bar-file doesn't contain the java-classes. Another JAR-file is created, containing the classes. This should be on the class path