0 Replies Latest reply on May 31, 2017 5:59 PM by William Alves

    Richfaces 4.5.17 menuitem action method not being fired

    William Alves Newbie

      Hello developers !!

       

      I am migrating a web application from JEE5 to JEE7. My problem concerns to the presentation layer.

       

      All system pages are being migrated from RichFaces 3.3.3 to 4.5.17. I have been following the official migration guide ([https://developer.jboss.org/wiki/RichFacesMigrationGuide33x-4xMigration][1]), this forum and Stackoverflow. But none has provided me an solution to my problem:

       

      The app menu is built dinamically on the managedbean (not with tags on xhtml). It worked fine on RF 3.3.3, using the classes HtmlToolBar, HtmlDropDownMenu, HtmlMenuGroup and HtmlMenuItem. However, after migrating to the RF4 corresponding classes, the menuitem action method is not called anymore. After the user clicks on the menuitem, the page refreshes and the request is made to the same page as actual, instead of the desired page.

      The migrated code follows below:

       

      Managedbean

      package br.gov.serpro.sfitweb.ui.managedbean;

      import java.io.Serializable;

      import javax.annotation.PostConstruct;
      import javax.el.ELContext;
      import javax.el.ExpressionFactory;
      import javax.enterprise.context.SessionScoped;
      import javax.faces.context.FacesContext;
      import javax.inject.Named;

      import org.apache.log4j.Logger;
      import org.richfaces.component.Mode;
      import org.richfaces.component.UIDropDownMenu;
      import org.richfaces.component.UIMenuGroup;
      import org.richfaces.component.UIMenuItem;
      import org.richfaces.component.UIToolbar;

      import br.gov.serpro.sfitweb.bean.entity.Usuario;
      import br.gov.serpro.sfitweb.bean.enums.Permissao;
      import br.gov.serpro.sfitweb.context.ContextFinder;
      import br.gov.serpro.sfitweb.context.SFITSecurityContext;

      @Named
      @SessionScoped
      public class MenuMBTrecho implements Serializable {
        
      private static final long serialVersionUID = 1L;

        
      private UIToolbar toolbar;

        
      public MenuMBTrecho() {
        
      }

        
      @PostConstruct
        
      public void init() {
        montarToolbar
      ();
        
      }

        
      public void montarToolbar() {
        
      FacesContext ctx = FacesContext.getCurrentInstance();

        
      this.toolbar = (UIToolbar) ctx.getApplication().createComponent(ctx, UIToolbar.COMPONENT_TYPE,
        
      "org.richfaces.ToolbarGroupRenderer");

        
      // log.debug("User" + secCtx.getUserPrincipal().getCpf());

        
      UIDropDownMenu menuPlanejamento = new UIDropDownMenu();
        menuPlanejamento
      .setLabel("Planejamento");
        
      boolean mostraMenu = false;

        
      ///////// Submenu PPA /////////
        
      boolean mostraSubMenuPPA = false;
        
      UIMenuGroup subMenuPPA = new UIMenuGroup();
        subMenuPPA
      .setLabel("PPA");

        
      UIMenuItem menuItem = new UIMenuItem();
        menuItem
      .setMode(Mode.ajax);
        menuItem
      .setLabel("Cadastrar período de PPA");
        
      ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
        
      ELContext ELCtx = FacesContext.getCurrentInstance().getELContext();
        menuItem
      .setActionExpression(
        factory
      .createMethodExpression(ELCtx, "#{ppaMB.listarPpas}", String.class, new Class[] {}));

        subMenuPPA
      .getChildren().add(menuItem);
        
      }

        
      public UIToolbar getToolbar() {
        
      return toolbar;
        
      }

        
      public void setToolbar(UIToolbar toolbar) {
        
      this.toolbar = toolbar;
        
      }
      }

       

      menu.xhtml

      <ui:composition xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:richext="http://java.sun.com/jsf/composite/richext"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
      xmlns:rich="http://richfaces.org/rich" xmlns:p="http://primefaces.org/ui"> 

      <div
      id="menu"> <h:form id="menuForm"> <rich:toolbar binding="#{menuMB.toolbar}"/> </h:form> </div> 

      </ui:composition>

      common.xhtml

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
      <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j"> 

      <f:view
      contentType="text/html"> 
      <h:head> <ui:include src="/public/pages/scriptTags.xhtml" />
      </h:head>  <link rel="stylesheet" href="#{configMB.context}/public/resources/styles/richfaces.css" /> 
      <h:body onload="ajustaAltura();" style="width:100%; padding:0px; margin: 0px; border-spacing: 0px;">
      <h:form id="principalMenu"> 
      <rich:messages globalOnly="false" errorClass="errorFatalMessage" fatalClass="errorFatalMessage" infoClass="infoMessage"
      warnClass="warnMessage" showSummary="true" showDetail="true"> </rich:messages> 

      <ui:insert
      name="top">
           <ui:include src="/public/pages/top.xhtml" />
      </ui:insert>

      <ui:insert
      name="header">
           <ui:include src="/public/pages/header.xhtml" />
      </ui:insert>

      <ui:insert
      name="menu">
           <ui:include
      src="/private/pages/menu.xhtml" />
      </ui:insert> 

      <div
      id="corpo" align="center">
      <rich:panel style="width: 97%;border:0">
           <ui:insert name="body" />
      </rich:panel>
      </div>

      <ui:insert
      name="footer">
           <ui:include src="/public/pages/footer.xhtml" />
      </ui:insert>
      </h:form>
      </h:body>

      Please any help that points me at least to the cause of this problem would be appreciated.

       

      Thank you in advance !

       

      William