2 Replies Latest reply on Nov 24, 2009 9:59 AM by kalomo

    panelBar / panelBarItem - How expand/collapse on client usin

    ekoiti

      Hi,

      I need change dinamically a menu make with richfaces panelBar/panelBarItem.

      Can I change active panelBarItem using javascript ?
      How i do this ?

        • 1. Re: panelBar / panelBarItem - How expand/collapse on client
          dgreenbean

          I just had this same issue. Unfortunately, there's no good way to do this. There is, however, a hack:

          <rich:panelBar>
           <rich:panelBarItem id="panel1" />
           <rich:panelBarItem id="panel2" />
           <rich:panelBarItem id="panel3" />
          </rich:panelBar>
          <script>
           // <![CDATA[
           function switchToPanel(panel) {
           if (document.createEventObject) {
           var event = document.createEventObject();
           panel.firstChild.fireEvent('onclick', event);
           } else {
           var event = document.createEvent('MouseEvents');
           event.initEvent('click', true, true);
           panel.firstChild.dispatchEvent(event);
           }
           }
           // ]]>
          </script>
          <a4j:form>
           <a4j:commandButton value="test1"
           oncomplete="switchToPanel(#{rich:element('panel1'});" />
           <a4j:commandButton value="test2"
           oncomplete="switchToPanel(#{rich:element('panel2'});" />
           <a4j:commandButton value="test3"
           oncomplete="switchToPanel(#{rich:element('panel3'});" />
          </a4j:form>
          


          It would be really nice if the initialize function in the PanelBar prototype defined $(panelId).component to be equal to the PanelBar instance, similar to how the ProgressBar component works. Until then, the code above is a decent workaround.

          -David


          • 2. Re: panelBar / panelBarItem - How expand/collapse on client

            hey,
            i tried out your workaround but i get following error

            switchToPanel(#{rich:element('panel1'});" contains invalid expression(s): javax.el.ELException: Error Parsing: switchToPanel(#{rich:element('panel1'});
            


            Do i need something else?