1 2 Previous Next 29 Replies Latest reply on Nov 10, 2007 4:30 PM by kukeltje

    Combo Box in Form

    riket44

      Hi,

      I've got a question, here is a part of my form :

      <f:facet name="header">
       <h:outputText value="Produit desire: "/>
       </f:facet>
       <h:inputText value="#{var['Produit']}" />
      


      In my database i've got a table named PRODUCT with the ID and the NAME for each product. I wanted to replace the inputText by a combo box in which there will be the NAME of all the products.

      Is it possible ? If yes, I would like to know how do that... Thanks.

      Regards,

      R.

      PS: I'm using Jbpm 3.2 GA with MySQL 5.0.

        • 1. Re: Combo Box in Form
          riket44

          If somebody could have an example, it would be ok ;)
          I understand JSF but I don't really understand how to do in jBPM...

          (aaah my bad english, I can't say what I want :) )

          • 2. Re: Combo Box in Form
            kukeltje

            Do it the same as you normally would. The itemset comes from your database the selected item is just referenced the same way as with an input element.

            • 3. Re: Combo Box in Form
              jorges38

              Riket44,

              Were you able to create de combo box with the item list from de PRODUCT database (external table) ?....I am looking for some samples too.

              I have created de (product.hbm.xml) hibernate file and the Product Class with (getters and setters) and modified the hibernate.cfg.xml....but i am not able to make it work.

              does anyone can help? Any samples?

              Att.,
              Jorge

              I am also using Jbpm 3.2 GA.

              • 4. Re: Combo Box in Form
                kukeltje

                I am helping... but you guys have to come up with trials and errors which I can comment on. I'm not going to build a full example (unless one of you guys pays my upcoming holiday)

                • 5. Re: Combo Box in Form
                  riket44

                  Do we really need to create an hbm file ??!
                  Usually I have my forms.xml and each forms near : form.product.xhtml, form.example.xhtml ...

                  And for answer to jorges38, no I'm not able to do that for the moment... :(
                  Always looking for an example, I hope some people have one !

                  • 6. Re: Combo Box in Form
                    kukeltje

                    whether you need a hbm file is dependant on whether you want the object that provides the list to be persistent or not (in jbpm or outside in your domainmodel). For JSF it is not needed. If you want the outcome to be stored in a single jbpm variable (e.g. a string) there is already persistency.....

                    think simple...

                    • 7. Re: Combo Box in Form
                      jorges38

                      I am sendig the coding that I have:

                      faces-config.xml

                      <!-- Catalog-->
                      <managed-bean>
                      <managed-bean-name>product</managed-bean-name>
                      <managed-bean-class>org.jbpm.webapp.bean.Product</managed-bean-class>
                      <managed-bean-scope>request</managed-bean-scope>
                      <managed-property>
                      <property-name>product</property-name>

                      </managed-property>
                      <managed-property>
                      <property-name>description</property-name>
                      #{description}
                      </managed-property>
                      <managed-property>
                      <property-name>situacao</property-name>
                      #{situacao}
                      </managed-property>
                      <managed-property>
                      <property-name>embalagem</property-name>
                      #{embalagem}
                      </managed-property>
                      <managed-property>
                      <property-name>tipo</property-name>
                      #{tipo}
                      </managed-property>
                      </managed-bean>
                      </faces-config>

                      In the Form:
                      ex. form.product.xhtml


                      <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"
                      xmlns:fmt="http://java.sun.com/jsp/jstl/fmt">
                      .
                      .
                      <ui:define name="body">
                      <!-- These aliases will save us a lot of typing -->
                      <ui:param name="bean" value="#{taskInstanceBean}"/>
                      <ui:param name="ti" value="#{taskInstanceBean.taskInstance}"/>
                      <ui:param name="td" value="#{taskBean.task}"/>
                      <ui:param name="pd" value="#{processBean.processDefinition}" />
                      <ui:component>
                      .
                      .
                      <jbpm:datacell>
                      <f:facet name="header">
                      Product ID
                      </f:facet>
                      <h:outputText value="#{ti.product}"/>
                      </jbpm:datacell>
                      .
                      .
                      Product.java

                      package org.jbpm.webapp.bean;

                      public class Product {
                      private Integer product=1;
                      private String description;
                      private String situacao;
                      private String embalagem;
                      private String tipo;

                      public Integer getProduct(){
                      return produto;
                      }

                      public void setProduto(Integer product){
                      this.product = product;
                      }

                      public String getDescription(){
                      return description;
                      }

                      public void setDescription(String description){
                      this.description = description;
                      }

                      public String getSituacao(){
                      return situacao;
                      }

                      public void setSituacao(String situacao){
                      this.situacao = situacao;
                      }

                      public String getEmbalagem(){
                      return embalagem;
                      }

                      public void setEmbalagem(String embalagem){
                      this.embalagem = embalagem;
                      }

                      public String getTipo(){
                      return tipo;
                      }

                      public void setTipo(String tipo){
                      this.tipo = tipo;
                      }

                      }

                      • 8. Re: Combo Box in Form
                        kukeltje

                        here you use your object as a variable type in jbpm. Then you need a hbm file in jbpm.. correct. I normally do not do it this way. We have our domain model outside of the engine.

                        But still.. what is the issue with this? What do you expect from me? I need errors, explicit questions etc.... just (parts of) something is not what I can work with.

                        • 9. Re: Combo Box in Form
                          roccolocko

                          Well, this have nothing to do with JBPM but still here is the change you have to do to create a combo in your JSF page:

                          
                          <h:selectOneMenu id="yourComboId"
                           value="#{yourBean.yourProperty}"
                           styleClass="combobox"
                           >
                           <f:selectItems id="yourItemId"
                           value="#{yourBean.yourList}"/>
                           </h:selectOneMenu>
                          
                          


                          I know its not much but you didn't posted much neither.

                          • 10. Re: Combo Box in Form
                            kukeltje

                            Thanks Rocco, I hoped they themselves would have come up with even a simple thing like this.

                            If you change #{yourBean.yourProperty} with e.g. #{proccesVar1} the yourBean does not even have to be a processVariable or whatever. It can be any bean outside jbpm.

                            • 11. Re: Combo Box in Form
                              riket44

                              Hello,

                              Well, I will put all my code, because I have an error I can't found (since 2 days !!! )

                              First, here is my form :

                               <jbpm:datacell>
                              
                               <f:facet name="header">
                               <h:outputText value="Produit desire: "/>
                               </f:facet>
                              
                               <h:selectOneMenu value="#{genList.value}">
                               <f:selectItems value="#{genList.items}" />
                               </h:selectOneMenu>
                              
                               </jbpm:datacell>
                              



                              Here is my genList.java :
                              public class genList {
                              
                               private String value="";
                               private Connection conn;
                              
                               public genList() {}
                              
                               public String getValue() {
                               return value;
                               }
                               public void setValue(String value) {
                               this.value = value;
                               }
                              
                               public Collection getItems() {
                              
                               Collection items = new ArrayList();
                               SelectItem si = null;
                              
                               try{
                               //-- Connexion
                               Class.forName("com.mysql.jdbc.Driver");
                               conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/databaseName", "root", " ");
                              
                               //-- Creation du statement et de la requete
                               Statement stmt = conn.createStatement();
                               String requete = null;
                               requete = "SELECT ID_,NOM_ FROM materiel";
                              
                               //-- Execution de la requete
                               ResultSet rs = stmt.executeQuery(requete);
                              
                               //-- Lecture des donnees
                               while (rs.next())
                               {
                               si = new SelectItem (String.valueOf(rs.getInt(1)), rs.getString(2));
                               items.add(si);
                               }
                              
                               //-- Deconnexion
                               conn.close();
                               } catch(Exception e){
                               System.out.println("\n\n\nCONNEXION ECHOUEE: "+e+"\n\n\n");
                               System.exit(-1);
                               }
                              
                               return items;
                               }
                              }
                              


                              And finally here is my Face Config :
                               <managed-bean>
                              <managed-bean-name>genList</managed-bean-name>
                              <managed-bean-class>com.demande.action.genList</managed-bean-class>
                               <managed-bean-scope>request</managed-bean-scope>
                               </managed-bean>
                              



                              When I want to start my process I always have this error :

                              Argument Error: An option for component j_id48 was not an instance of javax.faces.model.SelectItem. Type found: java.util.ArrayList.
                              (j_id48 is the name given automatically to the combo box)

                              I tried a lot of things to repair that error, but nothing works... I can't see where is the problem, if you could help me, I will be very happy !

                              Thanks,

                              • 12. Re: Combo Box in Form
                                kukeltje

                                this is generic jsf stuff. please ask in the jsf forums...

                                • 13. Re: Combo Box in Form
                                  jorges38

                                  I am having the same problem:

                                  Argument Error: An option for component mycomboid was not an instance of javax.faces.model.SelectItem. Type found: java.util.ArrayList.

                                  mycomboid = id for the selectOneMenu

                                  Riket44, did you find a solution?

                                  • 14. Re: Combo Box in Form
                                    kukeltje

                                    please.... what is so difficult about my previous post.... this is JSF stuff, not jBPM. So please ask in the correct forum and learn JSF!!!! Btw.... Google (or Yahoo, Altavista, search.nl or whatever really IS your friend)

                                    JSF, selectitems, example great keywords to search on, but I bet you already figured that out yesterday

                                    1 2 Previous Next