cancel
Showing results for 
Search instead for 
Did you mean: 

How can I display the Form in Boriwser

al_lv
Champ in-the-making
Champ in-the-making
Hey all,

I try to start my Process programmatically, not in Activiti Explorer.
The process should start with a form: <startEvent id="theStart" activiti:formKey="resources/bookorder.form" />

What should I do, to see a form in browser.

I start and deploy a process in a servlet. This is a code:

public class ActivitiTestServlet extends HttpServlet {
   private static final long serialVersionUID = 1L;
   RepositoryService repositoryService;
   RuntimeService runtimeService;
   FormService formService;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ActivitiTestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

   /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      try{
         
      buildProcessEngine();
      response.setStatus(200);
      
      PrintWriter writer = response.getWriter();
      
      writer.println("<html>");
      writer.println("<head><title>Hello World Servlet</title></head>");
      writer.println("<body>");
      writer.println("   <h1>Hello World from a Sevlet!</h1>");
      writer.println("<body>");
      writer.println("</html>");
         
      writer.close();
      }
      
      catch (Exception e){
         System.out.println("Fehler: " + e);
         response.setStatus(404);
      }
   }

   /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
   }

   public void buildProcessEngine(){
      ProcessEngine processEngine = new ProcessEngineBuilder()
      .configureFromResource("activiti.cfg.xml")
      .buildProcessEngine();
      
      getServices(processEngine);
      deploy();
   }
   
   public void deploy(){

      String barFileName = "D:/workspace/ActivitiTestServlet/src/barFiles/bookorder.bar";
      ZipInputStream inputStream = null;
      try {
         inputStream = new ZipInputStream(new FileInputStream(
               barFileName));
      } catch (FileNotFoundException e) {
         System.out.println(e);
         e.printStackTrace();
      }
      repositoryService.createDeployment().name(barFileName)
            .addZipInputStream(inputStream).deploy();
      
      runtimeService.startProcessInstanceByKey("bookorder");
   }
   
   public void getServices(ProcessEngine processEngine){
      repositoryService = processEngine.getRepositoryService();      
      runtimeService = processEngine.getRuntimeService();
      formService = processEngine.getFormService();
   }
}

Can I put the rendered HTML-String in the writer?
I tried to get the form with code: writer.println(formService.getRenderedStartForm("processDefId"));
Is it correct? How get I a processDefinitionId?

Best regards

Alexej
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
Hi,

I don't think it's any problem to display the HTML by writing it to the response.

You can get hold of the process-definition using a process-definition-query

repositoryService.createProcessDefinitionQuery().processDefinitionKey("bookorder").singleResult();
Or use the started processInstance's getProcessDefinitionId() method.

al_lv
Champ in-the-making
Champ in-the-making
thanks.
I think it should work, but i have another problem:
I have five deloyments of this process.
How can I delete them all, without to drop my DB?
For instance deleteDeploymentByKey or so…?

Alexej

frederikherema1
Star Contributor
Star Contributor
You said it Smiley Wink

First query for all deployments, for each of them call RepositoryService.deleteDeployment(xxx).

You should checkout the javadocs for the API, this contains a quick overview about what is possible with our API: http://activiti.org/javadocs/index.html

al_lv
Champ in-the-making
Champ in-the-making
I read a javadoc, but it wasn't so clear for me.
The DeploymentQuery and ProcessDefinitionQuery have a same descripion….

Is it so correct:

  List<Deployment> deployments = repositoryService.createDeploymentQuery().deploymentName("Book order").list();
 
 
  for (int i = 0;i<deployments.size();++i){
   Deployment deployment = deployments.get(i);
   repositoryService.deleteDeployment(deployment.getId());
  }

I'v got it. The correct code:
  List<ProcessDefinition> processDefinitions =  repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_ID).list();
 
 
  for (int i = 0;i<processDefinitions.size();i++){  
   repositoryService.deleteDeployment(processDefinitions.get(i).getDeploymentId());
  }
Getting started

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.