1 2 3 Previous Next 33 Replies Latest reply on Feb 28, 2007 4:52 AM by avbentem

    jpdl-3.2.Beta2: how to access variable from task form in jPD

      For a demo I'm trying to extend the websale example with a simple condition, but am getting to feel stupid as I cannot find a way to access the value of 'quantity'...

      The variable has been defined in the forms, such as form.create.xhtml, just as provided in the sample code:

      <h:inputText
       value="#{var['quantity']}"
       converter="javax.faces.Integer"
       converterMessage="The quantity must be numeric."
       validatorMessage="The quantity must be at least 1.">
       <f:validateLongRange minimum="1"/>
      </h:inputText>


      In procesdefinition.xml I'm trying:

      <decision name="Large quantity?">
       <transition name="No" to="ship item">
       </transition>
       <transition name="Yes" to="Make appointment">
       <condition expression="#{contextInstance.variables['quantity'] gt 10}">
       </condition>
       </transition>
      </decision>


      Of course I tried many other ways, including "#{var['quantity'] gt 10}", CDATA, and even comparing string values. No matter what, I keep getting:

      org.jbpm.graph.node.Decision
      decision didn't select transition, taking default Transition(No)


      When also adding this specific variable to a controller then the value as entered in the task form (jbpm-console) is not preserved (not shown in the next forms), so that does not seem to be the correct way to do things either:

      <start-state name="Create new web sale order">
       <task swimlane="buyer" >
       <controller>
       <variable name="quantity" mapped-name="quantity"></variable>
       </controller>
       </task>
       <transition to="Evaluate web order" />
      </start-state>


      I know I can delegate the decision to a Java class, but if I understand correctly than the above should really not be too hard to achieve at all, right...?

      Thanks for any hints!
      Arjan.

        • 1. Re: jpdl-3.2.Beta2: how to access variable from task form in
          kukeltje

          try reversing the transitions

          • 2. Re: jpdl-3.2.Beta2: how to access variable from task form in

             

            "kukeltje" wrote:
            try reversing the transitions

            Thanks for the hint, but in fact I already did, which then resulted in the first transition to be always selected with the very same message. So: that gave me another default transition (as expected), but the condition itself never evaluates to true...

            So, at first glance, the condition looks OK to you?

            Regards,
            Arjan.

            • 3. Re: jpdl-3.2.Beta2: how to access variable from task form in
              kukeltje

              uhhmmm... it does... wellll it did.... in the testcases I see

              <condition expression='#{customer.number > 5}' />"


              so a real > instead of gt

              • 4. Re: jpdl-3.2.Beta2: how to access variable from task form in

                 

                "kukeltje" wrote:
                so a real > instead of gt

                Hmmm, I tried that too, with and without CDATA (and without whitespace which was listed as a bug), and also using an equals to avoid problems. Same issue...

                 <condition expression='#{customer.number > 5}' />"
                


                OK, I wonder where "customer.number" is defined; in a task form like in websale? I did not find any example that accesses variables that are defined in the task form (like in the first code fragment in my first post), but I forgot to search the test cases as well... So, I should indeed find the above test case. I am not at the same computer right now and not in the office on Monday, but I'll report back...

                Thanks,
                Arjan.


                • 5. Re: jpdl-3.2.Beta2: how to access variable from task form in
                  kukeltje

                  Now I officially should SHOUT: 'look at the testcases' but since you probably live close by I will not do that look myself.....<20 second delay>.... just did and I can say that customer is the variable name

                  so in your situation that should be

                  <condition expression="#{quantity > 10}">
                  


                  • 6. Re: jpdl-3.2.Beta2: how to access variable from task form in

                     

                    "kukeltje" wrote:
                    Now I officially should SHOUT: 'look at the testcases'


                    Yes, but thanks for not shouting. I really thought I did all I could think of as for searching the samples, the forum, and all universes next to ours... On the other hand: getting replies this fast makes me wonder why I did not ask around here much earlier -- shame on YOU ;-)

                    Anyway:
                    <condition expression="#{quantity > 10}">


                    I really think I tried that as well, but I'll need to do it again. Next time I will list all I did so I can be sure when at another computer. For now I'm sorry to say that I probably won't test until Tuesday, unless I set up the environment on this computer as well...

                    Arjan.
                    (not too close, in Haarlem)

                    • 7. Re: jpdl-3.2.Beta2: how to access variable from task form in
                      kukeltje

                      Haarlem... ooooohhhhhhhh ...... STFF, RTFM, GOOGLE IS YOUR FRIEND... THE SOURCE IS OPEN YOU KNOW.... :-)

                      I was just experimenting with some new things myself (security in seam) and looking at extending the identity/authorization solutiuon in jbpm to be a real pluggable service, so I had no real work at hand and was able to respond this quickly.

                      I myself found out that if I forgot a closing } in seam, el expressions always return false, so it might be this happend to you to by accident and the reason it did not work was different than you thought.

                      • 8. Re: jpdl-3.2.Beta2: how to access variable from task form in

                         

                        "kukeltje" wrote:
                        Haarlem... ooooohhhhhhhh ...... STFF, RTFM, GOOGLE IS YOUR FRIEND... THE SOURCE IS OPEN YOU KNOW.... :-)

                        Too bad there's no direct train connection since the latest time table was introduced for the Dutch railways ;-)

                        Arjan.

                        • 9. Re: jpdl-3.2.Beta2: how to access variable from task form in

                           

                          "kukeltje" wrote:
                          in the testcases I see
                          <condition expression='#{customer.number > 5}' />"


                          Errrrr, where did you find that test case? I cannot even find the string "customer.number" in the distributions at SourceForge, nor when I check out either jbpm.3 HEAD or version 3_1_beta2 from CVS... I'm certainly overlooking something here! [yes, feeling stupid...]

                          I did find other tests such as /src/java.jbpm.test/org/jbpm/jpdl/xml/files (used by XmlSchemaTest.java), DecisionExpressionTest.java and DecisionConditionsTest.java -- but those have variables set in code, using

                          processInstance.getContextInstance().setVariable("name", value);


                          Like I wrote: all I actually want is some demo of a condition based on variables as set in a simple task form...

                          I used :pserver:anonymous@jbpm.cvs.sourceforge.net:/cvsroot/jbpm for CVS, and http://sourceforge.net/project/showfiles.php?group_id=70542 for jbpm-jpdl-suite-3.2.Beta2.zip

                          By the way: no luck with, for example:
                          <decision name="Fits in mailbox">
                           <transition name="Yes" to="ship item">
                           <condition expression="#{quantity==1}"/>
                           </transition>
                           <transition name="No" to="Inform customer">
                           <condition expression="#{quantity!=1}"/>
                           </transition>
                          </decision>


                          Thanks,
                          Arjan.

                          • 10. Re: jpdl-3.2.Beta2: how to access variable from task form in
                            kukeltje

                            Arjan,

                            It should not matter wheter the variables are set via code or the webconsole. Both use the api. The testcase I looked at is in org/jbpm/jpdl/ from cvs DecisionExpression/condition/ strange.... does quantity have a value at all in your case? turn on debug to see if it does...

                            • 11. Re: jpdl-3.2.Beta2: how to access variable from task form in

                               

                              "kukeltje" wrote:
                              does quantity have a value at all in your case? turn on debug to see if it does...

                              Yes, it gets a value in the first form (that is, of course: if I enter a value). Then it is retrieved for the next forms, but not explicitly (or not at all) retrieved when the form "Evaluate web order" immediately continues at the Fork, which after my changes moves on to the Decision before going to Ship Item... This might be fine, though I suddenly noticed a different token: "shipping" rather than root:

                              [GraphElement] event 'task-create' on 'Task(Create new web sale order)' for 'Token(/)'
                              [TaskInstanceVariableMap] fetched value 'null' for task variable 'quantity'
                              [TaskInstanceVariableMap] fetched value 'null' for task variable 'quantity'
                              [TaskInstanceVariableMap] fetched value 'null' for task variable 'quantity'
                              [TaskInstanceVariableMap] fetched value 'null' for task variable 'quantity'
                              [TaskInstanceVariableMap] setting task variable 'item' from 'null' to 'My test item'
                              [TaskInstanceVariableMap] setting task variable 'quantity' from 'null' to '1'
                              [TaskInstanceVariableMap] setting task variable 'address' from 'null' to 'My address'
                              [VariableContainer] create variable 'quantity' in 'TokenVariableMap3286a' with value '1'
                              [GraphElement] event 'task-end' on 'Task(Create new web sale order)' for 'Token(/)'
                              
                              [GraphElement] event 'task-start' on 'Task(Evaluate web order)' for 'Token(/)'
                              [TaskInstanceVariableMap] fetched value '1' for task variable 'quantity'
                              [TaskInstanceVariableMap] fetched value '1' for task variable 'quantity'
                              [TaskInstanceVariableMap] Not changing value for variable quantity
                              [GraphElement] event 'task-end' on 'Task(Evaluate web order)' for 'Token(/)'
                              
                              [GraphElement] event 'node-leave' on 'Fork(salefork)' for 'Token(/shipping)'
                              [GraphElement] event 'transition' on 'Transition(shipping)' for 'Token(/shipping)'
                              [GraphElement] event 'node-enter' on 'Decision(Fits in mailbox)' for 'Token(/shipping)'
                              [Decision] decision didn't select transition, taking default Transition(Yes)
                              [Decision] decision Fits in mailbox is taking 'Transition(Yes)'
                              [GraphElement] event 'node-leave' on 'Decision(Fits in mailbox)' for 'Token(/shipping)'
                              [GraphElement] event 'transition' on 'Transition(Yes)' for 'Token(/shipping)'
                              [GraphElement] event 'node-enter' on 'Node(ship item)' for 'Token(/shipping)'
                              [ShipItem] ### grover now ships My test item to My address
                              [GraphElement] event 'node-leave' on 'Node(ship item)' for 'Token(/shipping)'


                              Above the log states "task variable". Maybe it's some other context? Earlier I tried using contextInstance.variables['quantity'] to no avail. http://docs.jboss.org/jbpm/v3/userguide/context.html does not give me other insight either, and Ship Item has no problem getting the variable in code, without caring for the token:

                              (String)contextInstance.getVariable("item")


                              However: I also noticed that in Wait for Money only the paymentId is fetched (not shown above, but no values for item, quantity and address are logged). So I guess only the variables that are listed in the form are actually retrieved; so then I should also somehow tell my Decision that some variables will be used? Do I need a Controller after all...?

                              Just for the sake of Google though I know it's going to be a long post: the above is logged when extending the websale example to the following processdefinition.xml, with no changes to the Java code:

                              <?xml version="1.0"?>
                              <process-definition name="websale" xmlns="urn:jbpm.org:jpdl-3.1">
                               <swimlane name="buyer" />
                              
                               <swimlane name="salesman">
                               <assignment actor-id="ernie" />
                               </swimlane>
                              
                               <swimlane name="accountant">
                               <assignment actor-id="bert" />
                               </swimlane>
                              
                               <swimlane name="shipper">
                               <assignment actor-id="grover" />
                               </swimlane>
                              
                               <start-state name="Create new web sale order">
                               <task swimlane="buyer" />
                               <transition to="Evaluate web order" />
                               </start-state>
                              
                               <task-node name="Evaluate web order">
                               <task swimlane="salesman">
                               <timer duedate="20 seconds" repeat="10 seconds">
                               <action class="org.jbpm.websale.RemindActor">
                               <swimlaneName>salesman</swimlaneName>
                               </action>
                               </timer>
                               </task>
                               <transition name="OK" to="salefork" />
                               <transition name="More info needed" to="Fix web order data" />
                               </task-node>
                              
                               <task-node name="Fix web order data">
                               <task swimlane="buyer" />
                               <transition to="Evaluate web order" />
                               </task-node>
                              
                               <fork name="salefork">
                               <transition name="payment" to="Wait for money" />
                               <transition name="shipping" to="Fits in mailbox" />
                               </fork>
                              
                               <task-node name="Wait for money">
                               <task swimlane="accountant" />
                               <transition to="update books" />
                               </task-node>
                              
                               <node name="update books">
                               <action class="org.jbpm.websale.UpdateBooks">
                               <msg>accountancy application is now informed of the payment</msg>
                               </action>
                               <transition to="salejoin" />
                               </node>
                              
                               <decision name="Fits in mailbox">
                               <transition name="Yes" to="ship item">
                               <condition expression='#{quantity==1}'/>
                               </transition>
                               <transition name="No" to="Inform customer">
                               <condition expression='#{quantity!=1}'/>
                               </transition>
                               </decision>
                              
                               <task-node name="Inform customer">
                               <task name="Call customer"></task>
                               <transition name="Customer informed" to="ship item"></transition>
                               </task-node>
                              
                               <node name="ship item">
                               <action class="org.jbpm.websale.ShipItem">
                               <swimlaneName>shipper</swimlaneName>
                               <msg>${shipper} now ships ${item} to ${address}</msg>
                               </action>
                               <transition to="salejoin" />
                               </node>
                              
                               <join name="salejoin">
                               <transition to="end" />
                               </join>
                              
                               <end-state name="end" />
                              </process-definition>

                              ...and gpd.xml:
                              <?xml version="1.0" encoding="UTF-8"?>
                              <process-diagram name="websale" width="566" height="541">
                               <node name="Create new web sale order" x="250" y="50" width="200" height="40">
                               <transition>
                               <label x="5" y="-10"/>
                               </transition>
                               </node>
                               <node name="Evaluate web order" x="280" y="125" width="140" height="40">
                               <transition name="OK">
                               <label x="9" y="-10"/>
                               </transition>
                               <transition name="More info needed">
                               <label x="-44" y="-18"/>
                               <bendpoint w1="-114" h1="-35" w2="116" h2="-35"/>
                               </transition>
                               </node>
                               <node name="Fix web order data" x="50" y="125" width="140" height="40">
                               <transition>
                               <label x="5" y="-10"/>
                               <bendpoint w1="109" h1="32" w2="-121" h2="32"/>
                               </transition>
                               </node>
                               <node name="salefork" x="250" y="200" width="200" height="25">
                               <transition name="payment">
                               <label x="12" y="-18"/>
                               <bendpoint w1="145" h1="31" w2="0" h2="-52"/>
                               </transition>
                               <transition name="shipping">
                               <label x="10" y="10"/>
                               <bendpoint w1="-126" h1="4" w2="14" h2="-51"/>
                               </transition>
                               </node>
                               <node name="Wait for money" x="425" y="275" width="140" height="40">
                               <transition>
                               <label x="5" y="-10"/>
                               </transition>
                               </node>
                               <node name="update books" x="425" y="350" width="140" height="40">
                               <transition>
                               <label x="5" y="-10"/>
                               <bendpoint w1="-1" h1="34" w2="144" h2="-33"/>
                               </transition>
                               </node>
                               <node name="Fits in mailbox" x="140" y="247" width="140" height="40">
                               <transition name="Yes">
                               <label x="5" y="-10"/>
                               </transition>
                               <transition name="No">
                               <label x="5" y="-14"/>
                               <bendpoint w1="-117" h1="1" w2="17" h2="-46"/>
                               </transition>
                               </node>
                               <node name="Inform customer" x="6" y="294" width="140" height="40">
                               <transition name="Customer informed">
                               <label x="-74" y="6"/>
                               <bendpoint w1="21" h1="51" w2="-116" h2="0"/>
                               </transition>
                               </node>
                               <node name="ship item" x="143" y="345" width="140" height="40">
                               <transition>
                               <label x="5" y="-10"/>
                               <bendpoint w1="30" h1="49" w2="-179" h2="1"/>
                               </transition>
                               </node>
                               <node name="salejoin" x="250" y="425" width="200" height="25">
                               <transition>
                               <label x="5" y="-10"/>
                               </transition>
                               </node>
                               <node name="end" x="280" y="500" width="140" height="40"/>
                              </process-diagram>

                              ...and forms.xml:
                              <?xml version="1.0" encoding="UTF-8"?>
                              <forms>
                               <form task="Create new web sale order" form="form.create.xhtml"/>
                               <form task="Evaluate web order" form="form.evaluate.xhtml"/>
                               <form task="Fix web order data" form="form.fix.xhtml"/>
                               <form task="Wait for money" form="form.money.xhtml"/>
                               <form task="Call customer" form="form.callcustomer.xhtml"/>
                              </forms>

                              ...and form.callcustomer.xhtml:
                              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
                              <html xmlns="http://www.w3.org/1999/xhtml"
                               xmlns:ui="http://java.sun.com/jsf/facelets"
                               xmlns:c="http://java.sun.com/jstl/core"
                               xmlns:h="http://java.sun.com/jsf/html"
                               xmlns:f="http://java.sun.com/jsf/core"
                               xmlns:tf="http://jbpm.org/jsf/tf"
                               xmlns:jbpm="http://jbpm.org/jsf">
                               <ui:component>
                               <jbpm:dataform>
                               <f:facet name="header">
                               <h:outputText value="#{taskName}"/>
                               </f:facet>
                               <jbpm:datacell>
                               <f:facet name="header">
                               <h:outputText value="Informed whom"/>
                               </f:facet>
                               <h:inputText value="#{var['Informed whom']}" />
                               </jbpm:datacell>
                               <jbpm:datacell>
                               <f:facet name="header">
                               <h:outputText value="Delivery date"/>
                               </f:facet>
                               <h:inputText value="#{var['Delivery date']}" />
                               </jbpm:datacell>
                               <jbpm:datacell>
                               <f:facet name="header">
                               <h:outputText value="Actions"/>
                               </f:facet>
                               <tf:saveButton value="Save"/>
                               <tf:cancelButton value="Cancel"/>
                               <tf:transitionButton value="Save and Close"/>
                               </jbpm:datacell>
                               </jbpm:dataform>
                               </ui:component>
                              </html>


                              • 12. Re: jpdl-3.2.Beta2: how to access variable from task form in
                                kukeltje

                                You do not seem to have any variables declared in the tasks and yes you need a controller there. afaik, the variables are transient if not declared on the task. In the other nodes they will not be available... again...afaik.

                                • 13. Re: jpdl-3.2.Beta2: how to access variable from task form in

                                  Hi there again!

                                  "kukeltje" wrote:
                                  You do not seem to have any variables declared in the tasks

                                  Errr, yes, I know. But any variable declared in the task forms is automagically available in other task forms that use the same variable names. Like:
                                  <h:inputText
                                   value="#{var['quantity']}"
                                   converter="javax.faces.Integer"
                                   converterMessage="The quantity must be numeric."
                                   validatorMessage="The quantity must be at least 1.">
                                   <f:validateLongRange minimum="1"/>
                                  </h:inputText>

                                  Even more: defining them in the task as well (in processdefinition.xml) makes the values NOT being available in other forms... This is exactly what made me ask how I can access a variable from a task form in jPDL (too bad the subject of forum posts is not truncated in the preview).

                                  "kukeltje" wrote:
                                  yes you need a controller there

                                  Are you referring to the Decision, or elsewhere...?

                                  By the way: I wonder if there's another way to define variables? I can image that in most cases one would not like to define the type and boundaries of a variable in multiple places, like 'converter' and 'minimum' for 'quantity' in both form.create.xhtml and form.evaluate.xhtml.

                                  Arjan.

                                  • 14. Re: jpdl-3.2.Beta2: how to access variable from task form in
                                    kukeltje

                                    I'm referring to the task nodes. not specificially the task forms

                                    Currently you have to define things in multiple forms since the core/default task controller does not take things into account. Defining types of variables on the process level is something that is currently under discussion. See the jira for this.

                                    I'll try to reproduce things tomorrow (hmmmm this morning :-) ) to see what the current behaviour is. It all sounds a bit strange.

                                    1 2 3 Previous Next