8 Replies Latest reply on Mar 23, 2009 11:28 AM by turpin_vincent

    task variable in java @endtask function

    turpin_vincent



      Hi, i'm using Seam 2.1 and i'm in trouble with task variable gestion

      In the third taskInstance  of a processInstance i want to get a variable (witch is in Process scope) in a function but i dont find how...

      In this part:


      `                  <h:column>
                              <f:facet name="plop">
                                  <h:outputText value="Voiture"/> 
                              </f:facet>
                              <h:outputText value="#{task.variables['sinistre'].typeVoiture}"/>  <br />
                         </h:column>
                             
                         <h:column>
                              <f:facet name="header"> 
                                  <h:outputText value="type de Voiture"/> 
                              </f:facet>
                              <h:inputText id="typeVoiture" value="#{Saisie_1.sinistre.typeVoiture}"/>                                                                 
                         </h:column>

                          <h:column>
                              <s:button value="ajouter" taskInstance="#{task}" action="#{Saisie_1.Ajout_Mat}" />                                                               
                          </h:column>`

      I update task variable {task.variables['sinistre'].typeVoiture} with a value from the input text {Saisie_1.sinistre.typeVoiture}
      and it works but then i want to get this value in my function in order to persist this value.


      `       @StartTask 
         @EndTask(transition="toJoin2")
         public void Ajout_Mat()
              {    
                 System.out.println("ajout du type de voiture");
                 System.out.println("voiture avant set: "+ sinistre.getTypeVoiture());
                 sinistre.setTypeVoiture(sinistre.getTypeVoiture());
                 System.out.println("voiture apres set: "+sinistre.getTypeVoiture());
                 this.ajouterInfoMat();
                 System.out.println("Sinistre mat maj et transmis");
              }
         `

      but i dont find how

      I give you all the files needed


      `package org.domain.Mutant.session;


      import java.util.List;

      import javax.persistence.EntityManager;

      import org.domain.booking.entity.Sinistre;
      import org.jboss.seam.annotations.bpm.CreateProcess;
      import org.jboss.seam.annotations.bpm.EndTask; 
      import org.jboss.seam.annotations.bpm.ResumeProcess;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name; 
      import org.jboss.seam.annotations.bpm.StartTask; 
      import org.jboss.seam.annotations.*; 
      import org.jboss.seam.bpm.TaskInstancePriorityList;
      import org.jboss.seam.ScopeType; 
      import org.jbpm.JbpmContext;
      import org.jbpm.graph.exe.ExecutionContext;
      import org.jbpm.graph.exe.ProcessInstance;
      import org.jbpm.taskmgmt.exe.TaskInstance;


      @Name("Saisie_1")
      public class Saisie_1


               @In EntityManager entityManager;
               ExecutionContext executionContext;

              
               @Out(scope=ScopeType.BUSINESS_PROCESS)
               private static Sinistre sinistre;
               
         public Sinistre getSinistre()
         {
                 if(sinistre == null)
                 {
                         sinistre = new Sinistre();
                 }
                
                 return sinistre;
              }

              public void setSinistre(Sinistre sinistre)
              {
                      Saisie_1.sinistre = sinistre;
              }
             
             
              @CreateProcess(definition="simple")
              public String startProcess()
          {  
                      System.out.println("process straté");   
                      sinistre = new Sinistre(getSinistre());
                      System.out.println("Sinistre crée avec les parametres suivants et sinistre: ");
                      System.out.println("id: " + sinistre.getIdSinistre());
                      System.out.println("nom: " + sinistre.getNomClient());
                      System.out.println("prénom: " +sinistre.getPrenomClient());
                      System.out.println("Corporel: " +sinistre.isSinistreCorporel());
                      System.out.println("Materiel: " +sinistre.isSinistreMateriel());
                      System.out.println("voiture: " +sinistre.getTypeVoiture());
                      System.out.println("blessure: " +sinistre.getTypeblessure());
                     
                      return "Mat";

         }
             
             
              @ResumeProcess
              @StartTask
              @EndTask(transition="toFork") 
              public void valider()
              { 
                 this.register();
                 System.out.println("Sinistre Sauvé et transmis");
         }

                
              @StartTask 
         @EndTask(transition="toJoin2")
         public void Ajout_Mat()
              {    
                 System.out.println("ajout du type de voiture");
                 System.out.println("voiture avant set: "+ sinistre.getTypeVoiture());
                 sinistre.setTypeVoiture(sinistre.getTypeVoiture());
                 System.out.println("voiture apres set: "+sinistre.getTypeVoiture());
                 this.ajouterInfoMat();
                 System.out.println("Sinistre mat maj et transmis");
              }
        
         @StartTask 
         @EndTask(transition="toJoin1")
         public void Ajout_Corp()
              { 
                 System.out.println("ajout du type de blessure");
                
                 System.out.println("blessure avant set: " +sinistre.getTypeblessure());
                 sinistre.setTypeblessure(sinistre.getTypeblessure());
                 System.out.println("blessure apres set: " +sinistre.getTypeblessure());
                 this.ajouterInfoCorp();
                 System.out.println("Sinistre mat maj et transmis");
              }

              @StartTask 
          @EndTask(transition="toFin")
          public void validFinal()
              { 
                 System.out.println("Sinistre saisie mis en base et clos");
              }
             
          public String register()
              {
                     
                      System.out.println("Sinistre mis en base avec les parametres suivants et sinistre: ");
                      System.out.println("id: " + sinistre.getIdSinistre());
                      System.out.println("nom: " + sinistre.getNomClient());
                      System.out.println("prénom: " +sinistre.getPrenomClient());
                      System.out.println("Corporel: " +sinistre.isSinistreCorporel());
                      System.out.println("Materiel: " +sinistre.isSinistreMateriel());
             
                      entityManager.persist(getSinistre());
                     
                      return "sinistre_created";
              }
         
          public String ajouterInfoMat()
              {
                  System.out.println("Voiture: " +sinistre.getTypeVoiture());
                 
                  entityManager.merge(sinistre);
                
                      return "voiture_ajoutée";
              }
         
          public String ajouterInfoCorp()
              {
                  System.out.println("Voiture: " +sinistre.getTypeblessure());
                 
                  entityManager.merge(sinistre);
                
                      return "blessure_ajoutée";
              }

      `

      `
      package org.domain.booking.entity;

      import java.io.Serializable;

      import javax.persistence.Entity;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Table;
      import javax.persistence.UniqueConstraint;

      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;

        • 1. Re: task variable in java @endtask function
          turpin_vincent

          @Entity
          @Name("sinistre")
          //@Scope(ScopeType.BUSINESS_PROCESS);
          @Table(name = "sinistre", uniqueConstraints =
                  {
                  @UniqueConstraint(columnNames = "idSinistre")
              })
          public class Sinistre implements Serializable
          {

                  private static final long serialVersionUID = 1L;
          /******************************************* Déclaration des variables ******************************************/
                 
                  @Id
                  @GeneratedValue(strategy = GenerationType.AUTO)
                  private Long idSinistre;
                  private String nomClient;
                  private String prenomClient;
                  private boolean sinistreCorporel;
                  private boolean sinistreMateriel;
                  private String typeVoiture;
                  private String typeblessure;


                  public Sinistre()
                  {

                  }
                 
                  public Sinistre(Sinistre sinistre)
                  {
                          this.setIdSinistre(null);
                          this.setNomClient(sinistre.getNomClient());
                          this.setPrenomClient(sinistre.getPrenomClient());
                          this.setSinistreCorporel(sinistre.isSinistreCorporel());
                          this.setSinistreMateriel(sinistre.isSinistreMateriel());
                          this.setTypeVoiture(null);
                          this.setTypeblessure(null);
                  }
          /************************************************ Getter et Setter **********************************************/

                 
                  public Long getIdSinistre()
                  {
                          return idSinistre;
                  }
                 
                  public void setIdSinistre(Long idSinistre)
                  {
                          this.idSinistre = idSinistre;
                  }
                 

                  public String getNomClient()
                  {
                          return nomClient;
                  }
                  public void setNomClient(String nomClient)
                  {
                          this.nomClient = nomClient;
                  }
                 
                  public String getPrenomClient()
                  {
                          return prenomClient;
                  }
                  public void setPrenomClient(String prenomClient)
                  {
                          this.prenomClient = prenomClient;
                  }
                 
                  public void setSinistreCorporel(boolean sinistreCorporel)
                  {
                          this.sinistreCorporel = sinistreCorporel;
                  }
                  public boolean isSinistreCorporel()
                  {
                          return sinistreCorporel;
                  }
                 
                  public void setSinistreMateriel(boolean sinistreMateriel)
                  {
                          this.sinistreMateriel = sinistreMateriel;
                  }
                  public boolean isSinistreMateriel()
                  {
                          return sinistreMateriel;
                  }

                  public void setTypeVoiture(String typeVoiture) {
                          this.typeVoiture = typeVoiture;
                  }

                  public String getTypeVoiture() {
                          return typeVoiture;
                  }

                  public void setTypeblessure(String typeblessure) {
                          this.typeblessure = typeblessure;
                  }

                  public String getTypeblessure() {
                          return typeblessure;
                  }



          }`



          `
          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich"
              template="layout/template.xhtml">
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

              <ui:define name="body">
                           <f:view> 
                              <h:form id="InfosVoiture">
                             
                              <h:outputText value="Il n'y a pas de sinistre a renseigner pour le moment" rendered="#{empty taskInstancePriorityList}"/>  

                                 <rich:panel>
                                  <f:facet name="header">Lsite des sinistre comportant une partie materiel </f:facet>
                                   <h:dataTable value="#{taskInstancePriorityList}"  
                          var="task" rendered="#{not empty taskInstancePriorityList}" 
                          bgcolor="#F1F1F1" border="10"> 
                              
                               <h:column> 
                                   <f:facet name="header"> 
                                       <h:outputText value="Creation"/> 
                                   </f:facet> 
                                   <h:outputText value="#{task.taskMgmtInstance.processInstance.start}"> 
                                       <s:convertDateTime type="date"/> 
                                   </h:outputText> 
                               </h:column>
                               
                                          <h:column>
                                                  <f:facet name="header"> 
                               <h:outputText value="Employe"/> 
                                  </f:facet>
                              <h:outputText value="#{task.actorId}"/> <br />
                                          </h:column> $
                                          <h:column>
                                                  <f:facet name="header"> 
                               <h:outputText value="task"/> 
                                  </f:facet>
                              <h:outputText value="#{task.name}"/> <br />
                                          </h:column>       
                                          <h:column>
                                                  <f:facet name="header"> 
                              <h:outputText value="Id du sinistre" /> 
                                  </f:facet>
                                  <h:outputText value="#{task.variables['sinistre'].idSinistre}" />  <br />
                                  </h:column>       
                                          <h:column>
                                                  <f:facet name="header"> 
                                  <h:outputText value="Nom du client"/> 
                                  </f:facet>
                                  <h:outputText value="#{task.variables['sinistre'].nomClient}" />  <br />
                             </h:column>    
                                          <h:column>
                                                  <f:facet name="header"> 
                                  <h:outputText value="Prenom du client"/> 
                                  </f:facet>       
                                  <h:outputText value="#{task.variables['sinistre'].prenomClient}"/>  <br />
                               </h:column>
                               <h:column>
                                                  <f:facet name="header"> 
                                  <h:outputText value="Corporel"/> 
                                  </f:facet>
                                  <h:outputText value="#{task.variables['sinistre'].sinistreCorporel}"/>  <br />
                                  </h:column>
                                  <h:column>
                                                  <f:facet name="header"> 
                              <h:outputText value="Materiel"/> 
                                  </f:facet>
                                  <h:outputText value="#{task.variables['sinistre'].sinistreMateriel}"/>  <br />
                                  </h:column>
                                 
                                  <h:column>
                                                  <f:facet name="header"> 
                              <h:outputText value="Voiture"/> 
                                  </f:facet>
                                  <h:outputText value="#{task.variables['sinistre'].typeVoiture}"/>  <br />
                                  </h:column>
                                 
                                  <h:column>
                                                  <f:facet name="header"> 
                              <h:outputText value="type de Voiture"/> 
                                  </f:facet>
                                          <h:inputText id="typeVoiture" value="#{Saisie_1.sinistre.typeVoiture}"/>                                                         
                                  </h:column>
                                  <h:column>
                                          <s:button value="ajouter" taskInstance="#{task}" action="#{Saisie_1.Ajout_Mat}" />                                                               
                                  </h:column>
                                 
                                 
                
                        </h:dataTable>
                        <div>
                   <h:commandButton value="Mise a jour des champs" action="update"/>
                </div>
                       
                                   </rich:panel>
                              </h:form> 
                          </f:view> 
              </ui:define>
          </ui:composition>`

                  

          So if someone can tell me how i can do that he (or she ;)) is welcome.

          thanks by advance

          Turpin vincent
          • 2. Re: task variable in java @endtask function
            mwohlf

            sorry, I didn't check all that code, but this is what works for me in a component:



                @In(scope = ScopeType.BUSINESS_PROCESS, required = false)
                @Out(scope = ScopeType.BUSINESS_PROCESS, required = false)
                private String processActorId;



            I also wondered why Saisie_1 doesn't implement Serializable and why sinistre is static, looks a bit strange at me, but that's just my first impression...

            • 3. Re: task variable in java @endtask function
              turpin_vincent

              Thanks for your reply, in fact it's in static because if not, value are cleaned when i leave the first task.
              I will try with your code and tell you what append.

              • 4. Re: task variable in java @endtask function
                mwohlf

                you can also check the JBPM_VARIABLEINSTANCE table to see if the variable gets persisted

                • 5. Re: task variable in java @endtask function
                  turpin_vincent
                  i'checked that

                  with:


                  @In(scope = ScopeType.BUSINESS_PROCESS, required = false)
                      @Out(scope = ScopeType.BUSINESS_PROCESS, required = false)
                      private String processActorId;

                  it work like with


                      @Out(scope = ScopeType.BUSINESS_PROCESS, required = false)
                      private static String processActorId;

                  but i still can't get the value

                         </f:facet>
                             <h:inputText id="typeVoiture" value="#{task.variables['sinistre'].typeVoiture}"/>
                         </h:column>

                  with:

                  System.out.println("voiture avant set: "+ sinistre.getTypeVoiture());

                  in order to persist it with :

                  entityManager.merge(sinistre);
                  • 6. Re: task variable in java @endtask function
                    mwohlf

                    you don't need to persist the task instances, Seam should do this job for you. I recommend you take a look at Dan Allen's Seam in Action chapter 14 is available online at http://www.manning.com/dallen/ and covers the jBPM stuff, (it's a great book BTW)

                    • 7. Re: task variable in java @endtask function
                      turpin_vincent

                      Thanks for this advice (even if i still read this chapter) i know that Seam should do that, but i need to persist some information from this task in a spécific table in order to deal with an other application. So i will read this doc with more attention and maybe buy this book.


                      Vincent Turpin

                      • 8. Re: task variable in java @endtask function
                        turpin_vincent
                        BTW is that possible to pass an argument by this way:

                        <h:column>
                               <s:button value="ajouter" taskInstance="#{task}" action="#{Saisie_1.Ajout_Mat(task.variables['sinistre'].typeVoiture})" />
                        </h:column>