0 Replies Latest reply on Jun 24, 2008 10:46 AM by Jan-Martijn Wijnholds

    Question about Page nav with a dynamic build: HtmlPanelMenu

    Jan-Martijn Wijnholds Newbie

      Hi everyone!

      I'm a bit new with JSF and Richfaces and i have a question i hope someone can anwser.

      I'm dynamicly building a HtmlPanelMenu in Java, but i don't realy understand how to use the menu to navigate through my webapplication.

      This is how i try to achieve it:

      in my template:

      <h:form id="form">
       <h:panelGrid id="paneldId" columns="2" columnClasses="cols"
       width="100%">
       <rich:panelMenu id="menuId" binding="#{userMenuController.panelMenu}" />
       </h:panelGrid>
       </h:form>
      


      my backing bean
      public class UserMenuController {
      
       private HtmlPanelMenu panelMenu = null;
      
       /*
       * The Spring Bean which provides the Kennisgebied services that do the JPA
       * queries
       */
       private KennisgebiedService kennisgebiedService;
      
       /**
       * @return the kennisgebiedService
       */
       public KennisgebiedService getKennisgebiedService() {
       return kennisgebiedService;
       }
      
       /**
       * @param kennisgebiedService
       * the kennisgebiedService to set
       */
       public void setKennisgebiedService(KennisgebiedService kennisgebiedService) {
       this.kennisgebiedService = kennisgebiedService;
       }
      
       /**
       * Creation of the <code>HtmlPanelMenu</code> based on the
       * 'Kennisgebieden', 'Kennisdomeinen' and 'Kennisdeelgebieden' found in the
       * model
       *
       * @return A HtmlPanelMenu witch can be used in
       * <code>kms-template.xhtml</code>
       */
       @SuppressWarnings("unchecked")
       public HtmlPanelMenu getPanelMenu() {
       if (panelMenu == null) {
      
       panelMenu = new HtmlPanelMenu();
       panelMenu.setId("panelMenu");
       panelMenu.setStyle("width:100%");
       panelMenu.setMode("ajax");
       panelMenu.setIconExpandedGroup("disc");
       panelMenu.setIconCollapsedGroup("disc");
       panelMenu.setIconExpandedTopGroup("chevronUp");
       panelMenu.setIconGroupTopPosition("left");
       panelMenu.setIconCollapsedTopGroup("chevronDown");
       panelMenu.setIconGroupTopPosition("left");
      
       FacesContext facesContext = FacesContext.getCurrentInstance();
       Application appl = facesContext.getApplication();
      
       Iterator iter = kennisgebiedService.getKennisgebieden(0, 0)
       .iterator();
      
       while (iter.hasNext()) {
       Kennisgebied kennisgebied = (Kennisgebied) iter.next();
      
       HtmlPanelMenuGroup menuItemKennisgebied = new HtmlPanelMenuGroup();
       menuItemKennisgebied.setLabel(kennisgebied.getTitel());
       menuItemKennisgebied.setName(kennisgebied.getTitel());
       menuItemKennisgebied.setIconCollapsed("triangle");
       menuItemKennisgebied.setIconExpanded("triangleDown");
       menuItemKennisgebied.setAction(appl.createMethodBinding("#{userMenuController.go}", new Class [0] ));
      
      
       Iterator iterKennisDomeinen = kennisgebied
       .getCollectieKennisDomein().iterator();
       while (iterKennisDomeinen.hasNext()) {
       Kennisdomein kennisdomein = (Kennisdomein) iterKennisDomeinen.next();
       HtmlPanelMenuItem menuItem_Kennisdomein = new HtmlPanelMenuItem();
       menuItem_Kennisdomein.setLabel(kennisdomein.getTitel());
       menuItem_Kennisdomein.setName(kennisdomein.getTitel());
      
       menuItem_Kennisdomein.setAction(appl.createMethodBinding("#{userMenuController.go}", new Class [0]));
      
       menuItemKennisgebied.getChildren().add(menuItem_Kennisdomein);
       }
      
       panelMenu.getChildren().add(menuItemKennisgebied);
       }
       }
      
       return panelMenu;
       }
      
       /**
       * Sets the panelMenu when a page is reloaded.
       *
       * @param panelMenu
       */
       public void setPanelMenu(HtmlPanelMenu panelMenu) {
       this.panelMenu = panelMenu;
       }
      
       public String go(){
       System.out.println("nav_to_kennisdomein_detailed: " + panelMenu.getSelectedChild());
       return "nav_to_kennisdomein_detailed";
       }
      }
      
      


      faces config:
       <navigation-rule>
       <navigation-case>
       <from-outcome>nav_to_kennisgebieden_overzicht</from-outcome>
       <to-view-id>/pages/kennisgebieden_overzicht.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <navigation-case>
       <from-outcome>nav_to_kennisdomein_detailed</from-outcome>
       <to-view-id>/pages/kennisdomein_detailed.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <navigation-case>
       <from-outcome>nav_to_kennisdeelgebied_detailed</from-outcome>
       <to-view-id>/pages/kennisdeelgebied_detailed.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <navigation-case>
       <from-outcome>nav_to_kenniskaart_detailed</from-outcome>
       <to-view-id>/pages/kenniskaart_detailed.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <navigation-case>
       <from-outcome>nav_to_kenniskaarten_overzicht</from-outcome>
       <to-view-id>/pages/kenniskaarten_overzicht.xhtml</to-view-id>
       </navigation-case>
       </navigation-rule>
      </faces-config>
      


      Now i have 2 questions:

      1) I now use the setAction on a HtmlPanelMenuItem and the seems to work. But when i do the same thing with my it does'n trigger the go() method. Does someone know if this is possible?

      2) After selecting a item in my menu, the target page has to be filled with the specific data. I would espect that i can get a ID, and search it the items in my model. can someone give me some tips?

      I hope someone can help me :)

      Thnx in advance!

      Jan-Martijn