3 Replies Latest reply on Jul 11, 2011 4:49 AM by Nikola Ninovic

    Executing code when panelMenuGroup collapses/expands

    Martin Dubuc Newbie

      I'd like to execute some code when panelGroupMenu expands or collapses. I tried to attach a method using changeExpandListener, but my method is not invoked when menu is expanded or collapsed. I am probably not defining the method with the proper signature. Somebody knows what is the method signature for a changeExpandListener menthod? I also would like to execute JavaScript code when menu is expanded/collapsed. I tried the onexpand and oncollapse properties of panelMenuGroup, but my JavaScript code is not executed. I have defined the groupMode as "server".

       

      Martin

        • 1. Executing code when panelMenuGroup collapses/expands
          Martin Dubuc Newbie

          The reason I am trying to exexute code when panelMenuGroup is expanded/collapsed is to trrack value of expanded property. I have defined expanded property as :

           

          expanded="#{mybean.expanded}"

           

          The menu has the right expansion when first rendered, but when the expansion is changed, this value in the back end bean is not updated. I would like to execute some code in the back end when the expansionchanges to update my backing bean expanded property in order for menu to be rendered with appropriate expansion next time the form is refreshed.

           

          Martin

          • 2. Executing code when panelMenuGroup collapses/expands
            Martin Dubuc Newbie

            I found out researching this issue that the onbeforeexpand and onbeforecollapse properties in the rich:panelMenuGroup were good placeholders for executing JavaScript code. I still haven't figured out how to get the changeExpandListener to work in a backing bean, but in the meantime, I trigger code to execute on expand and collapse which updates a h:inputHidden field on my page that gets submitted when the form refreshes (groupMode is set to server to force page submit on expand/collapse) and that I use to keep track of the status of the expand state of the panelMenuGroup.

             

            Martin

            • 3. Re: Executing code when panelMenuGroup collapses/expands
              Nikola Ninovic Newbie

              Hi Martin,

               

              I had the same problem as you, and inspired by your post found another workaround.

               

              If you want you could use listeners for onbeforeexpand and onbeforecollapse events, or just onswitch listener, something like this

               

              <a4j:ajax event="switch" listener="#{leftMenu.switchEvent}" render="left_menu" limitRender="true" execute="@this"/>

              <a4j:param value="menu1" name="menu"/>

               

              public void switchEvent(AjaxBehaviorEvent event){

                 String menu  = FacesUtils.getParameterFromRequestMap("menu");

                 if(menu.equals("menu1"))

                 this.menu1 = !this.menu1;

                  ...

              }

               

              You could than read a4j parameter from request scope and set specific attribute to collapsed/expanded

               

              Regards

              Nikola