AnsweredAssumed Answered

How to start the task from Managed Bean?

Question asked by sherlock on Jan 28, 2013
Hi,
I am using Activiti-cdi,jsf for my project.
I have a situation that i'm merging start task and task complete actions on a single page.
So  for starting the task i have given Process Definition Key as parameter and starting the task by using
#{businessProcess.startProcessByKey(processDefinitionKey)}
.
And to open the assigned task
<f:event type="preRenderView"
         listener="#{businessProcess.startTask(taskId, true)}"   />
.
As i'm merging these  two actions on the same page, facing problems like processDefinitionKey is null or taskid is null.
So i want to write the listener action in Managed bean.
So my question is how to start the task from Managed bean to get the process variables on the UI to display..
My code is like

<f:metadata>
   <!– For create action –>
      <!– bind the key of the process to be started –>
         <f:viewParam name="processDefinitionKey" value="#{processList.processDefinitionKey}"  />
   
   <!– For pending action –>         
         <f:viewParam name="taskId" />
         <!– start working on the usertask and starting a conversation –>
      <f:event type="preRenderView"
         listener="#{businessProcess.startTask(taskId, true)}"   />
   <!– For rendering buttons –>      
      <f:event type="preRenderView"
         listener="#{customerController.renderButtons()}" />   
   </f:metadata>
<h:body>
<h:form>
<h:outputText value="Incident Title" />
<h:inputText value="#{processVariables['incidentTitle']}" />
<h:outputText value="Incident Date" />
<input type="date" name="incidate" value="#{processVariables['incidentDate']}"/>

<h:commandButton value="Submit" action="#{businessProcess.startProcessByKey(processList.processDefinitionKey)}" rendered="#{customerController.renderCrtSubmitButton}" />

<h:commandButton value="Submit" action="#{businessProcess.completeTask(true)}" rendered="#{customerController.renderActSubmitbutton}" />
</h:form>
</h:body>


@Named
@SessionScoped
public class CustomerController implements Serializable {
boolean renderCrtSubmitButton;
boolean renderActSubmitbutton;
public void renderButtons()
   {
      if(taskId==null||taskId.trim().isEmpty())
      {
      renderCrtSubmitButton=true;
      renderActSubmitbutton=false;
      }
      else
      {
         renderCrtSubmitButton=false;
         renderActSubmitbutton=true;
      }
   }
}

Thanks
Sherlock

Outcomes