5 Replies Latest reply on Apr 9, 2008 9:22 AM by Rangel Preis

    CommandLink with PanelMenu doesn't work (reRender)?

    Rangel Preis Newbie

      I try this code... when user click on the command link the MenuPanel will refresh it value. But it's doesn't work, the PanelMenu doesn't work refresh.

      If i refresh the page (press F5 ) it shows the menu but do nothing when click in command link.

      Someone can help me? Why it doesn't work?

      I'm using tomcat 6.0.15, jsf 1.2, richfaces 3.1.2 SP1.

      JSF code

      <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      
      <f:view>
       <a4j:form>
       <table width="200">
       <tr>
       <td><table width="200">
       <tr>
       <td><a4j:commandLink value="Administrativo" action="#{panelMenu.criaMenu1}" reRender="menu"/></td>
       <td><a4j:commandLink value="Financeiro" action="#{panelMenu.criaMenu2}" reRender="menu"/></td>
       </tr>
       <tr>
       <td>
       <br>
       <br>
       <br>
       <br>
       <br>
       </td>
       </tr>
       </table>
       <table width="200">
       <tr>
      
       <td>
       <rich:panelMenu id="menu" binding="#{panelMenu.menu2}" mode="ajax"/>
       </td>
       <td> </td>
       </tr>
       </table>
       </td>
       </tr>
       </table>
       </a4j:form>
      </f:view>
      


      JAVA code


      package com.agriness.sandboxjsf.presentation.web.jsf;
      
      import javax.faces.context.FacesContext;
      import javax.faces.event.ActionEvent;
      
      import org.richfaces.component.UIPanelMenuItem;
      import org.richfaces.component.html.HtmlPanelMenu;
      import org.richfaces.component.html.HtmlPanelMenuGroup;
      import org.richfaces.component.html.HtmlPanelMenuItem;
      
      public class PanelMenu {
       private Object current;
       private boolean singleMode;
      
      
       private HtmlPanelMenu menu2;
      
      
       public void criaMenu1(){
       HtmlPanelMenu menuAdm = new HtmlPanelMenu();
      
       HtmlPanelMenuGroup grupo1 = new HtmlPanelMenuGroup();
       grupo1.setName("Grupo1");
       grupo1.setLabel("Grupo1 - ADM");
      
       HtmlPanelMenuGroup grupo2 = new HtmlPanelMenuGroup();
       grupo2.setName("Grupo2");
       grupo2.setLabel("Grupo2 - ADM");
      
       HtmlPanelMenuItem menuItem1 = new HtmlPanelMenuItem();
       menuItem1.setName("Cadastrar");
       menuItem1.setLabel("Cadastrar");
      
       HtmlPanelMenuItem menuItem2 = new HtmlPanelMenuItem();
       menuItem2.setName("Consultar");
       menuItem2.setLabel("Consultar");
      
       HtmlPanelMenuItem menuItem3 = new HtmlPanelMenuItem();
       menuItem3.setName("Item2");
       menuItem3.setLabel("Item 2.1");
      
       HtmlPanelMenuItem menuItem4 = new HtmlPanelMenuItem();
       menuItem4.setName("Item3");
       menuItem4.setLabel("Item 2.2");
      
       grupo1.getChildren().add(menuItem1);
       grupo1.getChildren().add(menuItem2);
      
       grupo2.getChildren().add(menuItem3);
       grupo2.getChildren().add(menuItem4);
      
       menuAdm.getChildren().add(grupo1);
       menuAdm.getChildren().add(grupo2);
      
       menu2 = menuAdm;
       }
      
       public void criaMenu2(){
       HtmlPanelMenu menuFin = new HtmlPanelMenu();
       HtmlPanelMenuGroup grupo1 = new HtmlPanelMenuGroup();
       grupo1.setName("Grupo1");
       grupo1.setLabel("Grupo1 - FIN");
      
       //menuGroup.
      
       HtmlPanelMenuItem menuItem1 = new HtmlPanelMenuItem();
       menuItem1.setName("Cadastrar");
       menuItem1.setLabel("Cadastrar");
      
       HtmlPanelMenuItem menuItem2 = new HtmlPanelMenuItem();
       menuItem2.setName("Consultar");
       menuItem2.setLabel("Consultar");
      
       grupo1.getChildren().add(menuItem1);
       grupo1.getChildren().add(menuItem2);
      
       menuFin.getChildren().add(grupo1);
      
       menu2 = menuFin;
       }
      
      
       public void setSingleMode(boolean singleMode) {
       this.singleMode = singleMode;
       }
      
       public PanelMenu() {
       }
      
       public Object getCurrent() {
       return this.current;
       }
      
       public void setCurrent(Object current) {
       this.current = current;
       }
       public String updateCurrent() {
       FacesContext context=FacesContext.getCurrentInstance();
       setCurrent((String)context.getExternalContext().getRequestParameterMap().get("current"));
       System.out.println("fake called.");
       return null;
       }
       public void updateCurrent(ActionEvent event) {
       setCurrent(((UIPanelMenuItem)event.getComponent()).getLabel().toString());
       }
      
       public boolean isSingleMode() {
       return singleMode;
       }
      
       public HtmlPanelMenu getMenu2() {
       return menu2;
       }
      
       public void setMenu2(HtmlPanelMenu menu2) {
       this.menu2 = menu2;
       }
      }