9 Replies Latest reply on Feb 8, 2007 10:12 AM by morpheus_jboss

    How to get the jbpm context ?

    yegaofei888

      Hi All,

      I am converting the jbpm websales to jportal portlet.

      I found that: the

       JbpmContext.getCurrentJbpmContext()
      

      method doesn't work, in other words, it returns NULL

      But
      JbpmConfiguration.getInstance().createJbpmContext();
      

      works fine. It also can get the default jbpm context.

      I wonder if the second code is correct. Could you please tell me the differences between them?

      Thanks!

      My portal is 2.4.0 jboss is 4.0.4.GA and jbpm is 3.1.2

        • 1. Re: How to get the jbpm context ?

          I believe that, once you get a JbpmConfiguration instance and after you created a context with that instance, you can actually use getCurrentJbpmContext.

          Test this code:

          JbpmConfiguration config = JbpmConfiguration.getInstance();
          JbpmContext context = config.createJbpmContext();
          assertEquals(context, config.getCurrentJbpmContext());
          


          Let me know if that works for you.

          Regards.

          • 2. Re: How to get the jbpm context ?
            yegaofei888

            Hi cocampo,

            I mean if the

            JbpmContext.getCurrentJbpmContext()
            


            will work

            • 3. Re: How to get the jbpm context ?
              cpob

              You have to create the jbpm context first with

              JbpmConfiguration.getInstance().createJbpmContext();


              before you can get the current. Once you have created it, then you can get the current with
              JbpmContext.getCurrentJbpmContext()


              You've got to create something before you can get the current instance of it :)

              • 4. Re: How to get the jbpm context ?
                yangdaolin

                JbpmContext.getCurrentJbpmContext() is thread safe.

                When you call context object with:

                JbpmConfiguration.getInstance().createJbpmContext();

                You can get context object in current Thread only.

                • 5. Re: How to get the jbpm context ?
                  yegaofei888

                  Thank you !

                  Now I change the code UserBean.java like this:

                  public class UserBean {
                  
                   String userName;
                   static{
                   JbpmConfiguration.getInstance().createJbpmContext();
                   }
                  .........
                  
                  public String login() {
                   JbpmContext.getCurrentJbpmContext().setActorId(userName);
                   return "home";
                   }
                  
                  public List getUsers() {
                  
                   Session session = JbpmContext.getCurrentJbpmContext().getSession();
                   IdentitySession identitySession = new IdentitySession(session);
                   return identitySession.getUsers();
                   }
                  ..............
                  


                  I am not sure if this code will work fine when muilt users login at the same time

                  • 6. Re: How to get the jbpm context ?
                    yegaofei888

                    Sorry, I shall not put the code createing jbpm instantce into static block.

                    I move it to constructor

                    public UserBean(){
                     JbpmConfiguration.getInstance().createJbpmContext();
                    }
                    


                    • 7. Re: How to get the jbpm context ?
                      yegaofei888

                      Hi all,

                      My question is that in HomeBean.java, how to get the jbpm context, which was created in UserBean?

                      As in UserBean.java, it set the actorId, so I have to get the same jbpm context, and then I can get the same actor Id, not null value.

                      Shall I put this actor Id into portlet session, not jbpm context ?

                      • 8. Re: How to get the jbpm context ?
                        yangdaolin

                        If you can make sure that you use the HomeBean only in a thread, your codes is safe, otherwise you can't get current JbpmContext. you should put these into your porlet session. I want to know when you close JbpmContext.

                        • 9. Re: How to get the jbpm context ?
                          morpheus_jboss

                           

                          "yegaofei888@sohu.com" wrote:


                          I am converting the jbpm websales to jportal portlet.



                          Hi, I am doing the same thing. I am insterested in the questions asked here in this thread before. Namely, ActorId in portlet session or JbpmContext?

                          More generally, I know the portlet context is an extension of servlet context. but what is their relation to the jbpmContext if the jbpm Webapp is deployed as a portlet?