13 Replies Latest reply on Sep 21, 2006 10:23 AM by Ronald van Kuijk

    decision node with java code decision??

    mohammed lethrech Newbie

      i have created a DecisionHandler class, and put into it s decision methode the fololowing code :

      public String decide(ExecutionContext context) throws Exception {
       context.getContextInstance().setVariable("message", message);
       Object o=new Object();
       o=context.getVariable("Nom");
       //Nom it s a context variable
       if(o.toString().equals("maka"))
       return "transition1";
       else
       return "transition2";
       }
      


      after i have created a Node Leave action, then i attached my DecisionHandler class to Node Leave action.
      but the condition dont work?????
      anu idea??
      thankx a lot

        • 1. Re: decision node with java code decision??
          Konstantin Kolev Newbie

          Hi, lethrech!
          You must specify your decision handler implementation as value of the ¨handler¨ attribute of the decision node.
          The class specified in a node-leave action must implement ActionHandler not DecisionHandler. When leaving a node the method

          execute
          of this implementation is called and that? all.
          While on the other hand jBPM engine calls the
          decide
          method of your decision handler implementation to pick the appropriate transition. Be carefull because a transition name must be returned my this method not the
          to
          attribute of the decision.

          Saviola

          • 2. Re: decision node with java code decision??
            mohammed lethrech Newbie

            thanks saviola,
            but how to specify decision handler implementation as value of the "handler" attribut of the decision node?? using jbpm designer or i must add a tag or attribut in XML definition file??

            • 3. Re: decision node with java code decision??
              Konstantin Kolev Newbie

              Hi!
              For example like this:

              <decision name="Decision Node">
               <handler class="com.yourpackage.YourDecisionHandler"/>
              .
              .
              .
              </decision>
              


              Use the documentation! You will find a lot there, especially for the jPDL syntax:

              http://docs.jboss.com/jbpm/v3/userguide/jpdl.html#decision.element


              Regards,
              Saviola

              • 5. Re: decision node with java code decision??
                marco ferraz Newbie

                Hi lethrech and saviola!

                i have designed one simple process on the JBPM designer that works good, and now i am starting to complicate a little..
                I would like to include on the process definition one decision node!

                My idea is to make a decision node with two transition paths..
                I tried to put directly the code that u (Saviola) had sugested on other page.. on the source page of my process..




                ****
                ****<condition expression="#contextInstance.variables['Variavel'] ge 5"/>



                but to be honest i don´t understood the lines marked with ****!!
                what are the proposes of that lines?!
                and.. the Variavel? where and how can be defined?

                thanks Saviola..

                lethrech:

                Can you send me the DecisionHandler class that u made?so that i can see an example.. and then be capable of make my one decisonHandler class?
                marcoferraz65@hotmail.com

                thanks!!

                Sorry ir my questions are basic, but i am just starting

                • 6. Re: decision node with java code decision??
                  marco ferraz Newbie

                  Hi lethrech and saviola!

                  i have designed one simple process on the JBPM designer that works good, and now i am starting to complicate a little..
                  I would like to include on the process definition one decision node!

                  My idea is to make a decision node with two transition paths..
                  I tried to put directly the code that u (Saviola) had sugested on other page.. on the source page of my process..




                  ****
                  ****<condition expression="#contextInstance.variables['Variavel'] ge 5"/>



                  but to be honest i don´t understood the lines marked with ****!!
                  what are the proposes of that lines?!
                  and.. the Variavel? where and how can be defined?

                  thanks Saviola..

                  lethrech:

                  Can you send me the DecisionHandler class that u made?so that i can see an example.. and then be capable of make my one decisonHandler class?
                  marcoferraz65@hotmail.com

                  thanks!!

                  Sorry ir my questions are basic, but i am just starting

                  • 7. Re: decision node with java code decision??
                    Konstantin Kolev Newbie

                    Here is a more complete example:

                    <?xml version="1.0" encoding="UTF-8"?>
                    
                    <process-definition
                     xmlns="urn:jbpm.org:jpdl-3.1"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="urn:jbpm.org:jpdl-3.1 urn:jbpm.org/xsd/jpdl-3.1.xsd"
                     name="test">
                     <start-state name="start">
                     <transition name="" to="state1"></transition>
                     </start-state>
                     <state name="state1">
                     <event type="node-leave">
                     <script>
                     <variable name="aName" mapped-name="mappedName"/>
                     <expression>
                     executionContext.setVariable("mappedName", 7);
                     </expression>
                     </script>
                     </event>
                     <transition name="" to="decision1"></transition>
                     </state>
                     <decision name="decision1">
                     <transition name="" to="task1">
                     <condition expression="#{contextInstance.variables.mappedName le 5}"/>
                     </transition>
                     <transition name="tr2" to="task2">
                     <condition expression="#{contextInstance.variables.mappedName ge 5}"/>
                     </transition>
                     </decision>
                     <task-node name="task1">
                     <transition name="" to="end1"></transition>
                     </task-node>
                     <task-node name="task2">
                     <transition name="" to="end1"></transition>
                     </task-node>
                     <end-state name="end1"></end-state>
                    </process-definition>
                    

                    You can replace the first state part and the decision part with:
                     <state name="state1">
                     <event type="node-leave">
                     <script>
                     <variable name="aName" mapped-name="mappedName"/>
                     <expression>
                     executionContext.setVariable("mappedName", "tr1");
                     </expression>
                     </script>
                     </event>
                     <transition name="tr1" to="decision1"/>
                     </state>
                     <decision name="decision1">
                     <handler expression="#{contextInstance.variables['mappedName']}"/>
                     <transition name="tr1" to="task1"/>
                     <transition name="tr2" to="task2"/>
                     </decision>
                    


                    I hope this introduces some more clearness!

                    Regards,
                    Saviola

                    • 8. Re: decision node with java code decision??
                      Konstantin Kolev Newbie

                      I am sorry about the error but according to jPDL 3.1 the second part of the code needs to be corrected:

                      <handler expression="#{contextInstance.variables['mappedName']}"/>
                      

                      must be removed and the expression part must be moved to the decision node like this:
                      <decision name="decision1" expression="#{contextInstance.variables['mappedName']}">
                      ...
                      

                      Sorry about that - it's almost midnight :(

                      Saviola

                      • 9. Re: decision node with java code decision??
                        jainer eduardo quiceno Newbie

                        hi i've a problem that i have not to resolve.this is my code xml:

                        <?xml version="1.0" encoding="UTF-8"?>
                        <process-definition
                        xmlns="http://jbpm.org/3/jpdl" name="hello">
                        <!-- SWIMLANES -->









                        <!-- -->
                        <!-- NODES -->
                        <start-state name="comenzar">









                        </start-state>
                        <task-node name="mostrar variables">





                        <variable name="otra revision" access="read,write,required" mapped-name="decision">



                        </task-node>





                        <task-node name="revision diseñador">







                        </task-node>
                        <end-state name="end"></end-state>
                        </process-definition>

                        and this is the java code:
                        package com.hello;

                        import org.jbpm.graph.def.ActionHandler;
                        import org.jbpm.graph.exe.ExecutionContext;

                        public class HelloActionHandler implements ActionHandler {

                        private static final long serialVersionUID = 1L;

                        public void execute(ExecutionContext context) throws Exception{
                        decidir(context);
                        }

                        public String decidir(ExecutionContext context) throws Exception {

                        context.setVariable("message", "Hello from ActionHandler");
                        Object o = new Object();
                        o = context.getVariable("decision");
                        if ( o.toString().equals("si") )
                        return "enviar al diseñador";
                        else
                        return "terminar tarea";
                        }

                        }

                        And i've the next exception:
                        ype Exception report

                        message

                        description The server encountered an internal error () that prevented it from fulfilling this request.

                        exception

                        javax.servlet.ServletException: Error calling action method of component with id taskform:transitionButton
                        javax.faces.webapp.FacesServlet.service(FacesServlet.java:109)
                        org.jbpm.webapp.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:55)
                        org.jbpm.web.JbpmContextFilter.doFilter(JbpmContextFilter.java:83)
                        org.jbpm.webapp.filter.LogFilter.doFilter(LogFilter.java:59)
                        org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

                        root cause

                        javax.faces.FacesException: Error calling action method of component with id taskform:transitionButton
                        org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
                        javax.faces.component.UICommand.broadcast(UICommand.java:106)
                        javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
                        javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
                        org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:271)
                        org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
                        javax.faces.webapp.FacesServlet.service(FacesServlet.java:94)
                        org.jbpm.webapp.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:55)
                        org.jbpm.web.JbpmContextFilter.doFilter(JbpmContextFilter.java:83)
                        org.jbpm.webapp.filter.LogFilter.doFilter(LogFilter.java:59)
                        org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

                        note The full stack trace of the root cause is available in the Apache Tomcat/5.5 logs.


                        Any Question, thanx!!!!!!

                        • 10. Re: decision node with java code decision??
                          jainer eduardo quiceno Newbie

                          the message is bad typed, don't answer , please !!!!!
                          sorry!!!!!!!!!

                          • 11. Re: decision node with java code decision??
                            jainer eduardo quiceno Newbie

                             

                            "jainer" wrote:
                            hi i've a problem that i have not to resolve.this is my xml code:
                            
                            <?xml version="1.0" encoding="UTF-8"?>
                            <process-definition
                             xmlns="http://jbpm.org/3/jpdl" name="hello">
                             <!-- SWIMLANES -->
                             <swimlane name="ingeniero">
                             <assignment expression="user(faber aristizabal)" class=""></assignment>
                             </swimlane>
                             <swimlane name="diseñador">
                             <assignment expression="user(luis mantilla)" class=""></assignment>
                             </swimlane>
                             <swimlane name="secretaria">
                             <assignment expression="user(luz marina)" class=""></assignment>
                             </swimlane>
                             <!-- -->
                             <!-- NODES -->
                             <start-state name="comenzar">
                             <task name="enviar saludo" swimlane="secretaria">
                             <controller>
                             <variable name="saludo" access="read,write,required"></variable>
                             <variable name="nombre" access="read,write,required"></variable>
                             <variable name="apellido" access="read,write,required"></variable>
                             </controller>
                             </task>
                             <transition name="to_tasknode" to="mostrar variables">
                             </transition>
                             </start-state>
                             <task-node name="mostrar variables">
                             <task name="mostrar variables" swimlane="ingeniero">
                             <controller>
                             <variable name="saludo" access="read"></variable>
                             <variable name="nombre" access="read"></variable>
                             <variable name="apellido" access="read"></variable>
                             <variable name="otra revision" access="read,write,required" mapped-name="decision"></variable>
                             </controller>
                             </task>
                             <transition name="to_decision" to="existe revision"></transition>
                             </task-node>
                             <decision name="existe revision">
                             <handler class="com.hello.HelloActionHandler"/>
                             <transition name="enviar al diseñador" to="revision diseñador"/>
                             <transition name="terminar tarea" to="end"/>
                             </decision>
                             <task-node name="revision diseñador">
                             <task name="muestra variables" swimlane="diseñador">
                             <controller>
                             <variable name="nombre" access="read"></variable>
                             <variable name="apellido" access="read"></variable>
                             </controller>
                             </task>
                             <transition name="terminar tarea" to="end"></transition>
                             </task-node>
                             <end-state name="end"></end-state>
                            </process-definition>
                            


                            and this is the java code:
                            package com.hello;

                            import org.jbpm.graph.def.ActionHandler;
                            import org.jbpm.graph.exe.ExecutionContext;
                            
                            public class HelloActionHandler implements ActionHandler {
                            
                             private static final long serialVersionUID = 1L;
                            
                             public void execute(ExecutionContext context) throws Exception{
                             decidir(context);
                             }
                            
                             public String decidir(ExecutionContext context) throws Exception {
                            
                             context.setVariable("message", "Hello from ActionHandler");
                             Object o = new Object();
                             o = context.getVariable("decision");
                             if ( o.toString().equals("si") )
                             return "enviar al diseñador";
                             else
                             return "terminar tarea";
                             }
                            
                            }
                            


                            And i've the next exception:


                            type Exception report

                            message

                            description The server encountered an internal error () that prevented it from fulfilling this request.

                            exception

                            javax.servlet.ServletException: Error calling action method of component with id taskform:transitionButton
                            javax.faces.webapp.FacesServlet.service(FacesServlet.java:109)
                            org.jbpm.webapp.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:55)
                            org.jbpm.web.JbpmContextFilter.doFilter(JbpmContextFilter.java:83)
                            org.jbpm.webapp.filter.LogFilter.doFilter(LogFilter.java:59)
                            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

                            root cause

                            javax.faces.FacesException: Error calling action method of component with id taskform:transitionButton
                            org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
                            javax.faces.component.UICommand.broadcast(UICommand.java:106)
                            javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
                            javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
                            org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:271)
                            org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
                            javax.faces.webapp.FacesServlet.service(FacesServlet.java:94)
                            org.jbpm.webapp.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:55)
                            org.jbpm.web.JbpmContextFilter.doFilter(JbpmContextFilter.java:83)
                            org.jbpm.webapp.filter.LogFilter.doFilter(LogFilter.java:59)
                            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

                            note The full stack trace of the root cause is available in the Apache Tomcat/5.5 logs.


                            Any Question, thanx!!!!!!


                            • 12. Re: decision node with java code decision??
                              wehbe jean Newbie

                              same problem.
                              please i need the solution.

                              Jean Wehbe

                              • 13. Re: decision node with java code decision??
                                Ronald van Kuijk Master

                                look at the line:

                                note The full stack trace of the root cause is available in the Apache Tomcat/5.5 logs.


                                At least act on that....