7 Replies Latest reply on Dec 7, 2005 12:51 AM by Alejandro Guizar

    getVariable

    Doi Buon Newbie

      Hi all
      I'm new in jBPM.
      I have this problem.
      in

      <action class = "class">

      i have a variable name:
      List myValue

      this value i can get any where in my project with
      ExecutionContext.getVariable()

      but in webapp, i don't know what class allow getVariable from par project.
      Please help me.

        • 1. Re: getVariable
          Ronald van Kuijk Master

          Currently you can't. But soon you can. At least in a task page.

          • 2. Re: getVariable
            Doi Buon Newbie

            See:

            <task-node name="A">
             <task swimlane="st">
             <event type="task-create">
             <action class="path.B"/>
             </event>
             <controller>
             <variable name="help"
            ....


            In path.B i have some variables:

            public void execute(ExecutionContext executionContext) throws Exception {
             ContextInstance contextInstance = executionContext.getContextInstance();
            
             int ex=10;
             String test="test";
            
             contextInstance.setVariable("ex", ex);
            }

            I set the "ex" variable with contextInstance, with this command I want use it in the tag.

            but when i code
            <variable name="ex"/>

            Nothing change. please give me a correct command.
            Thanks.

            • 3. Re: getVariable
              Ronald van Kuijk Master

              what 'tag' do you mean?

              • 4. Re: getVariable
                Doi Buon Newbie

                 

                task-node name="L">
                 <task swimlane="st">
                 <event type="task-create">
                 <action class="j.C"/>
                 <script>
                 <expression>
                
                1. executionContext.getContextInstance().setVariable("stv", "11");
                 2. executionContext.getContextInstance().createVariable("test", "test"); </expression>
                 </script>
                 </event>
                 <controller>
                3. <variable name="test"/>
                 4. <variable name="stv"/> </controller>
                 </task>
                ....
                </task-node>

                why i create or set variable at line 1 and 2, value is not same/translate to variable in line 3 and 4.

                help me for crrect command line.
                thanks

                • 5. Re: getVariable
                  Tran Lap Newbie

                   

                  <task-node name="Lieu">
                   <task swimlane="st">
                   <event type="task-create">
                   <script>
                   <expression>
                   System.out.println("==="+executionContext.getContextInstance().getVariable("stv")+"====");
                  1. ArrayList list=new ArrayList();
                   list.add("ex1");
                   list.add("ex2");
                   2. String temp1="11";
                   </expression>
                   </script>
                   </event>
                   <controller>
                  3. <variable name="list"/>
                   4. <variable name='temp1'/>
                   </controller>
                   </task>
                   <transition name="tr1" to="Ket Thuc"></transition>
                   </task-node>

                  Please see this example.
                  I've created a variable with name="list" and other one with name="temp1"
                  and then i use "\<"controller"\>" tag to display two variables above.
                  I want when the WEBAPP display my "\<"controller"\>" will display with my value is setted at line 1 and 2, but when webapp display nothing be showed. WHY?
                  Please help me.

                  • 6. Re: getVariable
                    Alejandro Guizar Master

                    started working on this topic...

                    • 7. Re: getVariable
                      Alejandro Guizar Master

                      After spending more than an hour in completing a testable process definition:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <process-definition xmlns="http://jbpm.org/3/jpdl"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://jbpm.org/3/jpdl http://jbpm.org/xsd/jpdl-3.0.xsd"
                       name="loan-approval">
                       <start-state name="start">
                       <transition name="to-L" to="L"/>
                       </start-state>
                       <!--
                       <swimlane name="st">
                       <assignment class=""></assignment>
                       </swimlane>
                       -->
                       <task-node name="L">
                       <task name="t">
                       <controller>
                       <variable name="test" />
                       <variable name="stv" />
                       </controller>
                       <event type="task-create">
                       <script>
                       <expression>
                       executionContext.getContextInstance().setVariable("stv", new Integer(11));
                       executionContext.getContextInstance().createVariable("test", "eleven");
                       </expression>
                       </script>
                       </event>
                       </task>
                       <transition name="to-end" to="end"/>
                       </task-node>
                       <end-state name="end"/>
                      </process-definition>

                      And writing a unit test with persistence support that shows the problem:
                      package com.sample;
                      
                      import java.util.Collection;
                      import java.util.List;
                      
                      import junit.framework.TestCase;
                      
                      import org.jbpm.db.JbpmSession;
                      import org.jbpm.db.JbpmSessionFactory;
                      import org.jbpm.graph.def.ProcessDefinition;
                      import org.jbpm.graph.exe.ProcessInstance;
                      import org.jbpm.taskmgmt.exe.TaskFormParameter;
                      import org.jbpm.taskmgmt.exe.TaskInstance;
                      
                      public class Topic73364Test extends TestCase {
                      
                       private ProcessDefinition definition;
                      
                       private static JbpmSessionFactory jbpmSessionFactory = JbpmSessionFactory.buildJbpmSessionFactory();
                      
                       static {
                       // create the schema at runtime before we start the tests
                       jbpmSessionFactory.getJbpmSchema().createSchema();
                       }
                      
                       protected void setUp() throws Exception {
                       JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSessionAndBeginTransaction();
                       // Extract a process definition from the processdefinition.xml file.
                       definition = ProcessDefinition.parseXmlResource("topic73364.par/processdefinition.xml");
                       // Save and close
                       jbpmSession.getGraphSession().saveProcessDefinition(definition);
                       jbpmSession.commitTransactionAndClose();
                       }
                      
                       public void testSimpleProcess() throws Exception {
                       JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSessionAndBeginTransaction();
                       // Create an instance of the process definition.
                       ProcessInstance instance = new ProcessInstance(definition);
                       // Move the process instance from its start state to the first state.
                       instance.signal();
                       // Remember the instance identity
                       long instanceId = instance.getId();
                       // Save and close
                       jbpmSession.commitTransactionAndClose();
                      
                       jbpmSession = jbpmSessionFactory.openJbpmSessionAndBeginTransaction();
                       // Reload process instance
                       instance = jbpmSession.getGraphSession().loadProcessInstance(instanceId);
                       // one task instance
                       Collection taskInstances = instance.getTaskMgmtInstance().getTaskInstances();
                       assertEquals(1, taskInstances.size());
                       TaskInstance taskInstance = (TaskInstance) taskInstances.iterator().next();
                       // two parameters
                       List formParameters = taskInstance.getTaskFormParameters();
                       assertEquals(2, formParameters.size());
                       // parameter 'test'
                       TaskFormParameter formParameter = (TaskFormParameter) formParameters.get(0);
                       assertEquals("test", formParameter.getLabel());
                       assertEquals("eleven", formParameter.getValue());
                       // parameter 'stv'
                       formParameter = (TaskFormParameter) formParameters.get(1);
                       assertEquals("stv", formParameter.getLabel());
                       assertEquals(new Integer(11), formParameter.getValue());
                      
                       // Move the process instance to the end state
                       instance.signal();
                       assertTrue("Instance has ended", instance.hasEnded());
                       // Save and close
                       jbpmSession.commitTransactionAndClose();
                       }
                      }
                      

                      You didn't specify a version, so I assumed the latest stable version, 3.0.2. I was surprised to see that the test failed. I say failed in the QA sense here, because a test that finds no errors is a test that doesn't improve the quality of the product.

                      I took this post as a proof of how difficult is it to answer a seemingly obvious question with incomplete definitions, absent test cases and insufficient environment information. This is why we sometimes hesitate so much to try and answer.

                      In my opinion, we should create a sticky topic that establishes guidelines for acceptable postings and answer posts that do not comply with them with a single link to that topic. There is simply no way to reply to all questions from the community in the current state of things.