9 Replies Latest reply on Aug 26, 2008 1:27 PM by makabrus

    Adding SelectOneMenu through bean

    makabrus

      Hello,


      I need some help on adding a selectOneMenu to a page through the bean.
      The code I have is this:



      HtmlSelectOneMenu menu = new HtmlSelectOneMenu();
      menu.setValueExpression("value", createValueExpression("#{gestDocuments.selection}", String.class));
                          
      HtmlSelectItems items = new HtmlSelectItems();
      items.setValueExpression("value", createValueExpression("#{gestDocuments.selections}", String.class));
      
      items.setVar("var");
      items.setLabel("#{var}");
      menu.getChildren().add(items);
      dataGroup.getChildren().add(menu);



      but with this I'm having an exception:


      java.lang.NoClassDefFoundError: org/jboss/seam/ui/component/html/HtmlSelectItems



      Help appreciated!


      Thank you.

        • 1. Re: Adding SelectOneMenu through bean
          makabrus

          I managed to find another solution to this problem. Instead of adding the SelectOneMenu from the bean, I used conditional rendering.


          Alex

          • 2. Re: Adding SelectOneMenu through bean
            makabrus

            Well it seams my solution isn't a solution after all. I definitely need to generate the SelectOneMenu in the bean and add it to page.


            My code:


            HtmlSelectOneMenu select = new HtmlSelectOneMenu();
            select.setValueExpression("value", createValueExpression("#{gestDocuments.selection}", String.class));
            
            HtmlSelectItems items = new HtmlSelectItems();
            items.setValueExpression("value", createValueExpression("#{gestDocuments.selections}", List.class));
            items.setVar("_var");
            
            select.getChildren().add(items);
            dataTableGroup.getChildren().add(select); 



            I believe the error is lib related but i can't seem to fix it.
            This is kind of urgent, so please help if you can :)


            Thank you

            • 3. Re: Adding SelectOneMenu through bean
              michaelcourcy

              I guess you've double check that seam-ui.jar is available on the classpath when you deploy the app.


              May you decribe from where you called this code.

              • 4. Re: Adding SelectOneMenu through bean
                makabrus

                jboss-seam-ui.jar is in the WEB-INF\lib folder inside the war.


                I don't understand the second part of your reply :)


                Thank you

                • 5. Re: Adding SelectOneMenu through bean
                  michaelcourcy

                  Hum ...


                  I mean that if you call this code from an EJB (which I strongly suspect) the classpath is not the same, especially, jboss-seam-ui.jar is in projectDirectory/war/WEB-INF/lib but not in projectDirectory/lib.


                  While the classpath of your eclipse setup include jboss-seam-ui.jar, thus you cannot see the problem during dev.


                  Cheers

                  • 6. Re: Adding SelectOneMenu through bean
                    makabrus

                    It is being called as a result of an action in a seam component:


                    @Name("gestDocuments")
                    @Scope(ScopeType.SESSION)
                    public class GestaoDocumentsWS{
                    ...



                    jboss-seam-ui.jar is in project/lib and in the WEB-INF\lib of the war archive.



                    This is the code:



                    public void createTable(){
                         d = def_proxy.getDefinition(addDefName);
                    
                         dataTableGroup = new HtmlPanelGroup();
                         
                         List<Attribute> att = d.getAtributos();
                         
                         valores = new Object[att.size()];
                         menu = false;
                         
                         Attribute aux = new Attribute();
                         for(int i = 0; i < att.size(); ++i){
                              aux = att.get(i);
                              System.out.println(aux.getNomeAtributo() + " :: " + aux.getTipoAtributo());
                              HtmlOutputText output = new HtmlOutputText();
                              output.setValue(aux.getNomeAtributo());
                              dataTableGroup.getChildren().add(output);
                         
                              if(aux.isTipoMenu()){
                                   System.out.println("TIPO MENU");
                                   GestaoTiposService s = new GestaoTiposService();
                                   GestaoTipos p = s.getGestaoTiposPort();
                              
                                   selections = p.getValoresTipo(aux.getTipoAtributo());
                    
                                   //menu = true;
                                   
                    //               HtmlSelectOneMenu select = new HtmlSelectOneMenu();
                    //               select.setValueExpression("value", createValueExpression("#{gestDocuments.selection}", String.class));
                    //                    
                    //               HtmlSelectItems items = new HtmlSelectItems();
                    //               items.setValueExpression("value", createValueExpression("#{gestDocuments.selections}", List.class));
                    //               items.setVar("_var");
                    //               
                    //               select.getChildren().add(items);
                    //               dataTableGroup.getChildren().add(select);
                              }
                              else{
                                   if(aux.getTipoAtributo().equals("DATE")){
                                        HtmlCalendar myCalendar = new HtmlCalendar();
                                        myCalendar.setValueExpression("value", createValueExpression("#{gestDocuments.data}", Date.class));
                                        if(aux.isObrigatorio()){
                                             myCalendar.setRequired(true);
                                             myCalendar.setRequiredMessage(aux.getNomeAtributo() + ": Campo de preenchimento obrigatório.");
                                        }
                                        dataTableGroup.getChildren().add(myCalendar);
                                   }else{
                                        HtmlInputText input = new HtmlInputText();
                                        if(aux.isObrigatorio()){
                                             input.setRequired(true);
                                             input.setRequiredMessage(aux.getNomeAtributo() + ": Campo de preenchimento obrigatório.");
                                        }
                                        input.setValueExpression("value", createValueExpression("#{gestDocuments.valores[" + i + "]}", String.class));
                                        dataTableGroup.getChildren().add(input);
                                   }                    
                              }               
                         }
                    }



                    And I have the same error with HtmlCalendar, although the error happens when I deploy the application while the HtmlSelectOneMenu error only happens when the action is invoked.

                    • 7. Re: Adding SelectOneMenu through bean
                      makabrus

                      Ok, I changed a few lines of build.xml file and now I have this:


                      war\WEB-INF\lib:



                      • jboss-seam-debug.jar

                      • jboss-seam-gen.jar

                      • jboss-seam-ioc.jar

                      • jboss-seam-mail.jar

                      • jboss-seam-pdf.jar

                      • jboss-seam-remoting.jar

                      • jboss-seam-ui.jar



                      ear\lib:



                      • antlr-runtime.jar

                      • commons-beanutils.jar

                      • commons-collections.jar

                      • commons-digester.jar

                      • commons-lang.jar

                      • commons-logging.jar

                      • core.jar

                      • drools-compiler.jar

                      • drools-core.jar

                      • janino.jar

                      • jboss-el.jar

                      • jbpm-jpdl.jar

                      • jsf-facelets.jar

                      • mvel14.jar

                      • richfaces-api.jar

                      • richfaces-impl.jar

                      • richfaces-ui.jar



                      HtmlCalendar works fine now, but HtmlSelectItems still gives error.


                      Thank you.

                      • 8. Re: Adding SelectOneMenu through bean
                        blabno

                        Put jboss-seam-ui in the same place as jsf-facelets.jar . Since richfaces also need to be in the same folder as jsf-facelets.jar put them all in the same place.


                        Read this excellent article on classloading.

                        • 9. Re: Adding SelectOneMenu through bean
                          makabrus

                          Everything is working now :)


                          Thank you both!