0 Replies Latest reply on Mar 7, 2010 7:08 AM by mark lewis

    Dynamic rich:panelMenu usage

    mark lewis Newbie

      Hello

      Where can I get an example of how to create a dynamic rich:panelMenu including both the JSF, the java bean code and some form of illustration as to what it then looks like on the page? The RF demo doesn't include dynamically created panelMenus (or dropDowns which I hope I'll be able to apply the knowledge to).

       

      Thanks Mark

       

      *EDIT*

      Here's what I've got so far ripped partly from the RF demo

       

                      <h:form>
                          <a4j:region id="logs">
                              <h:panelGrid columns="2" border="1" width="100%" rowClasses="tt">
                                  <rich:panelMenu id="logPanelMenu" binding="#{PanelMenu.logPanelMenu}">
                                  </rich:panelMenu>
                                  <rich:panel style="width:65%"
                                      bodyClass="rich-laguna-panel-no-header">
                                      <a4j:outputPanel ajaxRendered="true">
                                          <h:outputText value="#{PanelMenu.current}" id="current" />
                                      </a4j:outputPanel>
                                  </rich:panel>
                              </h:panelGrid>
                          </a4j:region>
                      </h:form>

       

      [I'd highlight the above as XML but I've had it with this post editor]


       

       

      Java ripped from a forum which displays nothing (but at least it appears to build and deploy...):

       

      package myPkg;
      
      import javax.el.MethodExpression;
      import javax.faces.application.Application;
      import javax.faces.context.FacesContext;
      
      import org.richfaces.component.html.HtmlPanelMenu;
      import org.richfaces.component.html.HtmlPanelMenuGroup;     // not used at the moment.
      import org.richfaces.component.html.HtmlPanelMenuItem;
      
      public class PanelMenu {
          private String current;
          private boolean singleMode;
          private HtmlPanelMenu pmenu = new HtmlPanelMenu();
      
          public PanelMenu() {
          }
      
          public HtmlPanelMenu getLogPanelMenu() {
              if (pmenu == null) {
                  Application app = FacesContext.getCurrentInstance().getApplication();
                  pmenu = (HtmlPanelMenu) app.createComponent(HtmlPanelMenu.COMPONENT_TYPE);
      
                  pmenu.setMode("ajax");
                  pmenu.setExpandSingle(true);
                  pmenu.setId("logPanelMenu");
                  pmenu.setStyle("width:200px");
                  pmenu.setMode("ajax");
                  pmenu.setIconExpandedGroup("/img/logListFolderIconOpen.png");
                  pmenu.setIconCollapsedGroup("/img/logListFolderIconClosed.png");
                  pmenu.setIconExpandedTopGroup("/img/logListIcon.png");
                  pmenu.setIconGroupTopPosition("left");
                  pmenu.setIconCollapsedTopGroup("/img/logListIcon.png");
                  pmenu.setIconGroupTopPosition("left");
                  pmenu.setIconItem("/img/logFileIcon.png");
      
                  HtmlPanelMenuItem pMenuItem0 = (HtmlPanelMenuItem) app.createComponent(HtmlPanelMenuItem.COMPONENT_TYPE);
                  pMenuItem0.setName("Home");
                  pMenuItem0.setId("Home");
                  pMenuItem0.setLabel("Home");
                  MethodExpression me = app.getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "nav.home", null, new Class<?>[0]);
                  pMenuItem0.setActionExpression(me);
                  pmenu.getChildren().add(pMenuItem0);
      
      
                  HtmlPanelMenuItem pMenuItem1 = (HtmlPanelMenuItem) app.createComponent(HtmlPanelMenuItem.COMPONENT_TYPE);
                  pMenuItem1.setName("Templates");
                  pMenuItem1.setId("Templates");
                  pMenuItem1.setLabel("Templates");
                  me = app.getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "nav.templates", null, new Class<?>[0]);
                  pMenuItem1.setActionExpression(me);
                  pmenu.getChildren().add(pMenuItem1);
              }
              return pmenu;
          }
      
          public void setLogPanelMenu(HtmlPanelMenu menu) {
              pmenu = menu;    
          }   
      
          public String getCurrent() {
              return this.current;
          }
      
          public void setCurrent(String current) {
              this.current = current;
          }
      
          public String updateCurrent() {
              FacesContext context=FacesContext.getCurrentInstance();
              setCurrent((String)context.getExternalContext().getRequestParameterMap().get("current"));
              return null;
          }
      }
      

       

       

      I admit, I don't yet understand the use of MethodExpressions as I've not seen a decent source which explains in English how to use it step by step: just a bunch of javadocs with no explained examples.

       

      Any help much appreciated.

      Mark

       

      Added example code