1 Reply Latest reply on May 21, 2012 8:06 AM by Thadeu Rocha

    My sub-menus don't appear in UIToolBar

    Thadeu Rocha Newbie

      Hello guys, is my first post here.

       

      I have an application with a dynamic menu, i´m trying to migrate from richfaces 3.x to 4.x but it´s not working. I´ve searched another thread but I couldn´t find anything.

      Let start.

       

      web.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
                version="3.0">
                <description>Facelets StarterKit</description>
                <display-name>ScapWebMigracao</display-name>
                <context-param>  
              <param-name>org.richfaces.skin</param-name>  
              <param-value>blueSky</param-value>  
          </context-param>  
          <context-param>  
              <param-name>org.richfaces.fileUpload.maxRequestSize</param-name>  
              <param-value>100000</param-value>  
          </context-param>  
          <context-param>  
              <param-name>org.richfaces.fileUpload.createTempFiles</param-name>  
              <param-value>false</param-value>  
          </context-param> 
          <context-param>  
              <param-name>javax.faces.FACELETS_LIBRARIES</param-name>  
              <param-value>/WEB-INF/app-tags.taglib.xml</param-value>  
          </context-param> 
          <context-param>  
              <param-name>javax.faces.PROJECT_STAGE</param-name>  
              <param-value>Development</param-value>  
          </context-param>  
          <context-param>  
              <param-name>javax.faces.STATE_SAVING_METHOD</param-name>  
              <param-value>server</param-value>  
          </context-param>
          <context-param>
                          <param-name>com.sun.faces.validateXml</param-name>
                          <param-value>true</param-value>
                </context-param>
                <context-param>
                          <param-name>com.sun.faces.verifyObjects</param-name>
                          <param-value>true</param-value>
                </context-param>
                <context-param>
                          <param-name>com.sun.faces.expressionFactory</param-name>
                          <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
                </context-param>  
          <servlet>  
              <servlet-name>Faces Servlet</servlet-name>  
              <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>  
              <load-on-startup>1</load-on-startup>  
          </servlet>  
          <servlet-mapping>  
              <servlet-name>Faces Servlet</servlet-name>  
              <url-pattern>*.jsf</url-pattern>  
          </servlet-mapping>  
          <servlet-mapping>  
              <servlet-name>Faces Servlet</servlet-name>  
              <url-pattern>/faces/*</url-pattern>  
          </servlet-mapping>
          <servlet>
                          <servlet-name>CaptchaServlet</servlet-name>
                          <servlet-class>com.aspin.scapweb.servlet.CaptchaServlet</servlet-class>
                </servlet>
                <servlet-mapping>
                          <servlet-name>CaptchaServlet</servlet-name>
                          <url-pattern>/captcha.jpg</url-pattern>
                </servlet-mapping>  
                <session-config>
                          <session-timeout>20</session-timeout>
                </session-config>
                <listener>
                          <listener-class>com.aspin.scapweb.login.SessionController</listener-class>
                </listener>
          <mime-mapping>  
              <extension>xcss</extension>  
              <mime-type>text/css</mime-type>  
          </mime-mapping>  
          <login-config>  
              <auth-method>BASIC</auth-method>  
          </login-config>  
      </web-app>
      
      

       

      When i use the method getToolBar() he's calling this method:

       

      private void createMenu() {
                          int idMenuItem=0, idDropDownMenu = 0, idMenuGroup=0;
                          FacesContext facesContext = FacesContext.getCurrentInstance();
                          ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
        
                          List<MenuWeb> listMenuWeb = null;
        
                          try {
                                    MenuWebRG menuwebRG = new MenuWebRG();
                                    listMenuWeb = menuwebRG.findMenuWebUsuario(usuario, null); 
                          } catch (Exception e) {
                                    LogSistema.RegistraLog(this.getClass(), LogSistema.ERROR, "(createMenu): " + e.getMessage());
                          }
        
                          HashMap<Integer, UIComponent> hashMap = new HashMap<Integer, UIComponent>();
        
                          toolBar = (UIToolbar) facesContext.getApplication()
                            .createComponent(facesContext, UIToolbar.COMPONENT_TYPE, 
                            "org.richfaces.ToolbarRenderer");
        
                          UIComponent component = null;
        
                          for (MenuWeb menuweb : listMenuWeb) {
        
                                    if (menuweb.getNusuperior() == null || menuweb.getNusuperior().equals("")) { 
                                              UIDropDownMenu dropDownMenu = (UIDropDownMenu) facesContext.getApplication()
                                                .createComponent(facesContext, UIDropDownMenu.COMPONENT_TYPE,
                                                        "org.richfaces.DropDownMenuRenderer"); 
                                              dropDownMenu.setLabel(menuweb.getNmmenuweb());
                                              dropDownMenu.setMode(Mode.ajax);
                                              dropDownMenu.setId("dropDownMenu"+idDropDownMenu);
                                              toolBar.getChildren().add(dropDownMenu);
                                              hashMap.put(menuweb.getNumenuweb(), dropDownMenu);
                                              idDropDownMenu++;
        
                                    } else if (menuweb.getNmaplicacao() == null || menuweb.getNmaplicacao().equals("")) {
                                              UIMenuGroup menuGroup = (UIMenuGroup) facesContext.getApplication().createComponent(
                                                                  facesContext,UIMenuGroup.COMPONENT_TYPE,"org.richfaces.MenuGroupRenderer");
                                              menuGroup.setValue(menuweb.getNmmenuweb());
                                              menuGroup.setId("idMenuGroup"+idMenuGroup);
                                              component = hashMap.get(menuweb.getNusuperior()); 
                                              component.getChildren().add(menuGroup);
        
                                              idMenuGroup++;
        
                                              hashMap.put(menuweb.getNumenuweb(), menuGroup); 
                                    } else {
                                              UIMenuItem menuItem =  (UIMenuItem) facesContext.getApplication().createComponent(facesContext, 
                                          UIMenuItem.COMPONENT_TYPE,
                                          "org.richfaces.MenuItemRenderer");
                                              menuItem.setValue(menuweb.getNmmenuweb());
                                              menuItem.setMode(Mode.ajax);
                                              menuItem.setId("idMenuItem"+idMenuItem);
                                              MethodExpression methodExpression = expressionFactory.createMethodExpression(
                                                                  facesContext.getELContext(), "#{menu.selItem}",
                                                                  String.class, new Class[] {});
        
                                              menuItem.setActionExpression(methodExpression);
        
                                              UIParameter param = new UIParameter();
        
                                              param.setName("urlPagina");
                                              param.setValue(menuweb.getNmaplicacao());
        
                                              menuItem.getChildren().add(param);
        
                                              menuItem.setRender("incBody");
        
                                              menuItem.setExecute("@this");
        
                                              if(hashMap.get(menuweb.getNusuperior()) instanceof UIDropDownMenu){
                                                        component = (UIDropDownMenu)hashMap.get(menuweb.getNusuperior());
                                                        component.getChildren().add(menuItem);
                                              }else{
                                                        component = (UIMenuGroup)hashMap.get(menuweb.getNusuperior());
                                                        component.getChildren().add(menuItem);
                                              }
        
                                    } 
                          }
        
                }
      
      

       

      But my problem is, when i start the application my sub menus(UIMenuItem) don't appear.

      like this:

       

      Problem Richfaces 4.jpg

       

      So finally is this.
      I hope someone help !

       

      Cheers!!