5 Replies Latest reply on Jul 16, 2013 5:51 AM by dig1234

    How to access process variable in ftl file?

    pmuthuraman

      I am using the web based designer and have a process with a human task.  I have a ftl file attached to that human task and want to access process variables in the ftl file.  All the examples in this forum are related to the eclipse based designer.  Can someone let me know the steps to create the human task process in web based designer and how access the process variable in the ftl file?

        • 1. Re: How to access process variable in ftl file?
          tsurdilovic

          Hi, the jbpm web designer can generate task forms for you (see more on this here: https://hudson.jboss.org/hudson/job/jBPM/lastSuccessfulBuild/artifact/jbpm-distribution/target/jbpm-5.2.0-SNAPSHOT-docs-build/jbpm-docs/html/ch10.html and here: http://blog.athico.com/2011/07/develop-complex-jbpm-processes-all-in.html). These task forms (the process task form and a task form for each usertask in your process) are fully executeable and are stored in Guvnor, so you can modify them if needed.

           

          To answer your question, lets say you have a simple process:

           

          where you define two process variables, x and y of type string, if you generate the process forms and view the sources, you will see that to print out

          the value of x and y you could do for example:

           

           

          <div class="div_checkbox">
             ${x}
          </div>
          <div class="div_checkbox">
             ${y}
          </div>
          

           

          and to enter values of specific process variable or output mapping of your user task you can do for example:

           

          <form action="complete" method="POST" enctype="multipart/form-data" onsubmit="return taskFormValidator()">
             <div class="div_texbox">
                <input name="x" type="text" class="textbox" id="x" value="" />
             </div> 
          
             <label for="name">y</label>
             <div class="div_texbox">
                <input name="y" type="text" class="textbox" id="y" value="" />
             </div> 
          
             <div class="button_div">
                <input name="Submit" type="submit" value="Submit" class="buttons" />
             </div>
          </form>
          

           

          the JavaScipt, CSS and markup are not really needed, that's just something designer adds for the look/feel.

           

          Hope this helps.

          • 2. Re: How to access process variable in ftl file?
            pmuthuraman

            Thanks Tihomir for the reply.

             

            My java code to start the process has the below.

             




            Map<String, Object> params = new HashMap<String, Object>();



            params.put("policyId", "testingpolicyId");







            ksession.startProcess("voluntaryProcess", params);

             

            I have added the variable "policyId" in the variable definition property of my process. 

             

            process.JPG

             

             

             

            I am using guvnor 5.1 and the designer version is 1.0.0.55.

             

            When I tried to access my variable in the ftl file as ${policyId},  I am getting the below error.

             

            freemarker.core.InvalidReferenceException: Expression policyId is undefined on line 19, column 18 in ApprovedTask.

            freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)

            freemarker.core.Expression.getStringValue(Expression.java:118)

            freemarker.core.Expression.getStringValue(Expression.java:93)

            freemarker.core.DollarVariable.accept(DollarVariable.java:76)

            freemarker.core.Environment.visit(Environment.java:209)

            freemarker.core.MixedContent.accept(MixedContent.java:92)

            freemarker.core.Environment.visit(Environment.java:209)

            freemarker.core.Environment.process(Environment.java:189)

            freemarker.template.Template.process(Template.java:237)

            org.jbpm.integration.console.forms.AbstractFormDispatcher.processTemplate(AbstractFormDispatcher.java:116)

            org.jbpm.integration.console.forms.TaskFormDispatcher.provideForm(TaskFormDispatcher.java:119)

            org.jbpm.integration.console.forms.FormDispatcherComposite.provideForm(FormDispatcherComposite.java:50)

            org.jboss.bpm.console.server.FormProcessingFacade.provideForm(FormProcessingFacade.java:203)

            org.jboss.bpm.console.server.FormProcessingFacade.renderTaskUI(FormProcessingFacade.java:125)

            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

            java.lang.reflect.Method.invoke(Method.java:597)

            org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:117)

            org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:260)

            org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:232)

            org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:166)

            org.jboss.resteasy.core.DispatcherUtilities.getJaxrsResponse(DispatcherUtilities.java:142)

            org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)

            org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:173)

            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:93)

            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:68)

            javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

            org.jboss.bpm.console.server.util.GWTJsonFilter.doFilter(GWTJsonFilter.java:59)

            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

             

             

             

             

            Can you please let me know what is wrong?  Please let me know if you need any other information.

            • 3. Re: How to access process variable in ftl file?
              tsurdilovic

              Pretty hard to tell without being able to reproduce. Could you create a reproducible test for me to look at?

               

              Thanks.

              • 4. Re: How to access process variable in ftl file?
                krishanps

                Maybe it doesn't work because in the Variable Definitions there is only the variable name but not the type like in the first screenshot?

                Or you have to set up the property of the assignment of the task?

                 

                Do you solve the problem already?

                • 5. Re: How to access process variable in ftl file?
                  dig1234

                  Does the  question resolved ? I meet exactly the same problem when access process variable in .ftl, using the jbpm5.4 demo installer environment ,  any hints is welcome , thanks.

                   

                  Problem resolved: after review the evaluation example,

                  1)add a global variable named "content" ;

                  2) in userTask, mapping "content" to local Content property,by setting Content's value to content ;

                  3) add on entry action to initialize content variable <scripts> java.util.Map contentParam = new java.util.HashMap(); contentParam.put("username", username); kcontext.setVariable("content", contentParam); </scripts> ;

                  4) call directly in ftl with ${username}

                   

                  Thanks.