AnsweredAssumed Answered

How can I display the Form in Boriwser

Question asked by al_lv on Nov 22, 2010
Latest reply on Nov 22, 2010 by al_lv
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

Outcomes