2017-05-31 42 views
0

開發者!!Richfaces 4.5.17 Menuitem操作方法不起作用

我正在將Web應用程序從JEE5遷移到JEE7。我的問題涉及表示層。

所有系統頁面都從RichFaces 3.3.3遷移到4.5.17。我一直遵循正式的遷移指南([https://developer.jboss.org/wiki/RichFacesMigrationGuide33x-4xMigration][1]),Richfaces論壇(https://developer.jboss.org/en/richfaces),當然還有StackOverflow。但是沒有人爲我提供瞭解決我的問題的方法:

應用程序菜單是在managedbean上構建的(不包含xhtml上的標記)。它在RF 3.3.3上運行良好,使用類HtmlToolBar,HtmlDropDownMenu,HtmlMenuGroup和HtmlMenuItem。但是,在遷移到RF4相應的類後,MenuItem操作方法不再被觸發用戶單擊MenuItem後,頁面刷新並向當前頁面本身發出請求,而不是所需的頁面。

遷移的代碼如下所示:

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> 

</f:view> 
</html> 

faces-config.xml中

<?xml version="1.0"?> 
    <faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"> 

     <application> 
      <resource-bundle> 
       <base-name>br.gov.serpro.sfitweb.utils.MsgReaderUTF8</base-name> 
       <var>msg</var> 
      </resource-bundle> 
     </application> 

     <lifecycle> 
      <phase-listener>br.gov.serpro.sfitweb.ui.MessagePhaseListener</phase-listener> 
     </lifecycle> 

     <application> 
      <locale-config> 
       <default-locale>en</default-locale> 
      </locale-config> 
      <resource-bundle> 
       <base-name>com.example.faces.i18n.Text</base-name> 
       <var>text</var> 
      </resource-bundle> 
     </application> 

    </faces-config> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> 
    <display-name>sfitweb</display-name> 
    <distributable /> 

    <context-param> 
     <param-name>com.sun.faces.expressionFactory</param-name> 
     <param-value>com.sun.el.ExpressionFactoryImpl</param-value> 
    </context-param> 

    <!-- parametros necessario para processar os JS internos do Richfaces https://developer.jboss.org/thread/203506 --> 
    <context-param> 
     <param-name>org.richfaces.resourceOptimization.enabled</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <servlet> 
     <servlet-name>Resource Servlet</servlet-name> 
     <servlet-class>org.richfaces.webapp.ResourceServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Resource Servlet</servlet-name> 
     <url-pattern>/org.richfaces.resources/*</url-pattern> 
    </servlet-mapping> 


    <context-param> 
     <param-name>javax.faces.FACELETS_LIBRARIES</param-name> 
     <param-value>/WEB-INF/tomahawk.taglib.xml; 
      /WEB-INF/taglib/sfit.taglib.xml;</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.CONFIG_FILES</param-name> 
     <param-value>/WEB-INF/faces-config.xml</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.DEFAULT_SUFFIX</param-name> 
     <param-value>.xhtml</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
     <param-value>server</param-value> 
    </context-param> 
    <!-- parametros do Richfaces 4 --> 

    <context-param> 
     <param-name>org.richfaces.enableControlSkinning</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>org.richfaces.skin</param-name> 
     <param-value>wine</param-value> 
    </context-param> 
    <context-param> 
     <param-name>weblets.CONFIG_FILES</param-name> 
     <param-value>weblets-config.xml</param-value> 
    </context-param> 

    <!-- https://developer.jboss.org/wiki/RichFacesMigrationGuide33x-4xMigration-Upgrading 
     filtro do richfaces nao eh mais necessario no JSF 2 --> 
    <filter> 
     <filter-name>MyFacesExtensionsFilter</filter-name> 
     <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class> 
     <init-param> 
      <param-name>uploadMaxFileSize</param-name> 
      <param-value>20m</param-value> 
     </init-param> 
    </filter> 


    <filter-mapping> 
     <filter-name>MyFacesExtensionsFilter</filter-name> 
     <servlet-name>Faces Servlet</servlet-name> 
    </filter-mapping> 
    <listener> 
     <listener-class>com.sun.faces.config.ConfigureListener</listener-class> 
    </listener> 
<!-- <listener> --> 
<!--  <listener-class>br.gov.serpro.sfitweb.context.SFITSecurityServletRequestListener</listener-class> --> 
<!-- </listener> --> 
    <listener> 
     <listener-class>net.java.dev.weblets.WebletsContextListener</listener-class> 
    </listener> 
    <!-- WebService para consulta de permissoes --> 
    <listener> 
     <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    </servlet> 
    <servlet> 
     <servlet-name>Weblets Servlet</servlet-name> 
     <servlet-class>net.java.dev.weblets.WebletsServlet</servlet-class> 
    </servlet> 
    <servlet> 
     <servlet-name>ImageUploadServlet</servlet-name> 
     <servlet-class>br.gov.serpro.sfitweb.utils.ImageUploadServlet</servlet-class> 
    </servlet> 
    <servlet> 
     <servlet-name>ImageDownloadServlet</servlet-name> 
     <servlet-class>br.gov.serpro.sfitweb.utils.ImageDownloadServlet</servlet-class> 
    </servlet> 
    <servlet> 
     <servlet-name>PossuiPermissao</servlet-name> 
     <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Faces Servlet</servlet-name> 
     <url-pattern>*.jsf</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
     <servlet-name>Weblets Servlet</servlet-name> 
     <url-pattern>/weblets/*</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
     <servlet-name>ImageUploadServlet</servlet-name> 
     <url-pattern>/imageUpload</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
     <servlet-name>ImageDownloadServlet</servlet-name> 
     <url-pattern>/image</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
     <servlet-name>PossuiPermissao</servlet-name> 
     <url-pattern>/PossuiPermissao</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout>30</session-timeout> 
    </session-config> 
    <!-- Pages Configuration --> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 
    <error-page> 
     <error-code>404</error-code> 
     <location>/public/pages/error/HTTP404.jsf</location> 
    </error-page> 
    <error-page> 
     <error-code>500</error-code> 
     <location>/public/pages/error/HTTP500.jsf</location> 
    </error-page> 
    <error-page> 
     <exception-type>javax.faces.application.ViewExpiredException</exception-type> 
     <location>/public/pages/login.jsf</location> 
    </error-page> 
    <error-page> 
     <exception-type>java.lang.Throwable</exception-type> 
     <location>/public/pages/error/global.jsp</location> 
    </error-page> 
</web-app> 

請指向至少我對這個問題的原因任何幫助,將不勝感激。

預先感謝您!

威廉

+0

如果你有@action問題,你應該顯示它(並說出它應該做什麼),HTML部分在很大程度上是不相關的。 – Makhiel

+0

馬凱爾!謝謝回覆 !因爲它沒有被解僱,所以這個動作沒有關係。xhtml可能是相關的,因爲當RF4存在一些問題時,例如標籤未被放置(這導致RF4不加載JavaScript)。這就是我發佈xhtml文件的原因。另外,我剛剛發佈了web.xml和faces-config。謝謝 ! – Bill

+0

啊,看起來你有嵌套形式,擺脫他們。如果這沒有幫助嘗試手動創建菜單,並看看是否有效。 – Makhiel

回答

0

解決了!

1)改性的init()上ManagedBean:

@PostConstruct 
    public void init(){ 
     menuPlanejamento = (UIDropDownMenu)FacesContext.getCurrentInstance().getApplication().createComponent(UIDropDownMenu.COMPONENT_TYPE); 
} 

2.)上montarToolbar()方法增加了menuItem.setMode(Mode.ajax);

3)修改了XHTML頁面:

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

這就是它!