2014-10-31 71 views
2

我正在將一個非maven webapp項目遷移到maven,我遇到了一些問題。 我有我的頁面:<body>未在JSF上呈現的方法(onkeydown,onkeyup ...)

<h:body onkeydown="desabilitaEnterEnvioForm(event);" onkeyup="trocaComboBoxPesquisa(event);"> 
... 
</h:body> 

但在瀏覽器中呈現的HTML後我看到的是這樣的:

<body>...</body> 

出於某種原因,拿出身體的方法?哪些原因會導致這種奇怪的行爲?

UPDATE

我跑我的應用程序在Tomcat中8

這裏是我的web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     id="WebApp_ID" version="3.0"> 

    <display-name>Archetype Created Web Application</display-name> 

    <servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <servlet-class>javax.faces.webapp.FacesServlet</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> 
     <servlet-name>Jersey REST Service</servlet-name> 
     <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
     <init-param> 
      <param-name>com.sun.jersey.config.property.packages</param-name> 
      <param-value>br.atualy.gestao.restws</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>Jersey REST Service</servlet-name> 
     <url-pattern>/rest/*</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file>/login/login.jsf</welcome-file> 
    </welcome-file-list> 

    <context-param> 
     <param-name>primefaces.THEME</param-name> 
     <param-value>home</param-value> 
    </context-param> 

    <session-config> 
     <session-timeout>30</session-timeout> 
    </session-config> 
</web-app> 

這裏是我的faces-config.xml中:

<?xml version='1.0' encoding='UTF-8'?> 
<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"> 

    <navigation-rule> 
     <description>Voltar para o login</description> 
     <from-view-id>/*</from-view-id> 
     <navigation-case> 
      <from-outcome>Login</from-outcome> 
      <to-view-id>/login/login.xhtml</to-view-id> 
     </navigation-case> 
    </navigation-rule> 

</faces-config> 

UPDATE 2

我發現問題是由圖書館衝突(我認爲),因爲如果在我的pom.xml我只放了這些依賴它的工作原理造成的:

<dependency> 
    <groupId>org.glassfish</groupId> 
    <artifactId>javax.faces</artifactId> 
    <version>2.2.2</version> 
</dependency> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.0.1</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.el</groupId> 
    <artifactId>javax.el-api</artifactId> 
    <version>3.0.1-b04</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.servlet.jsp.jstl</groupId> 
    <artifactId>jstl-api</artifactId> 
    <version>1.2</version> 
</dependency> 

但是,如果我把我所有的項目依賴它會導致錯誤:

<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>3.8.1</version> 
    <scope>test</scope> 
</dependency> 

<dependency> 
    <groupId>org.glassfish</groupId> 
    <artifactId>javax.faces</artifactId> 
    <version>2.2.2</version> 
</dependency> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.0.1</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.el</groupId> 
    <artifactId>javax.el-api</artifactId> 
    <version>3.0.1-b04</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.servlet.jsp.jstl</groupId> 
    <artifactId>jstl-api</artifactId> 
    <version>1.2</version> 
</dependency> 


<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-entitymanager</artifactId> 
    <version>4.3.6.Final</version> 
</dependency> 

<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-c3p0</artifactId> 
    <version>4.3.6.Final</version> 
</dependency> 

<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-validator</artifactId> 
    <version>5.1.2.Final</version> 
</dependency> 

<dependency> 
    <groupId>org.primefaces</groupId> 
    <artifactId>primefaces</artifactId> 
    <version>5.1</version> 
</dependency> 

<dependency> 
    <groupId>org.omnifaces</groupId> 
    <artifactId>omnifaces</artifactId> 
    <version>1.8.1</version> 
</dependency> 

<dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-server</artifactId> 
    <version>1.17.1</version> 
</dependency> 

<dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-core</artifactId> 
    <version>1.17.1</version> 
</dependency> 

<dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-servlet</artifactId> 
    <version>1.17.1</version> 
</dependency> 

<dependency> 
    <groupId>br.atualy.util</groupId> 
    <artifactId>AtualyUtil</artifactId> 
    <version>1.0</version> 
</dependency> 

<dependency> 
    <groupId>br.atualy.temas</groupId> 
    <artifactId>home</artifactId> 
    <version>1.0.10</version> 
</dependency> 

<dependency> 
    <groupId>org.apache.axis2</groupId> 
    <artifactId>axis2-kernel</artifactId> 
    <version>1.5.4</version> 
</dependency> 

<dependency> 
    <groupId>org.apache.axis2</groupId> 
    <artifactId>axis2-adb</artifactId> 
    <version>1.5.4</version> 
</dependency> 

<dependency> 
    <groupId>net.sf.jasperreports</groupId> 
    <artifactId>jasperreports</artifactId> 
    <version>5.0.1</version> 
</dependency> 

<dependency> 
    <groupId>postgresql</groupId> 
    <artifactId>postgresql</artifactId> 
    <version>9.1-901-1.jdbc4</version> 
</dependency> 

<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.17</version> 
</dependency> 

也許某些這些依賴關係是錯誤的,但哪一個?

+0

我們應該如何認識?沒有任何真正相關的信息,比如你的pom文件有什麼樣的錯誤信息?你使用哪個maven版本等? – khmarbaise 2014-10-31 13:44:24

+0

冰雹!查看我更新的消息 – 2014-10-31 17:18:34

+0

您正在使用不同的faces實現...... javax.faces(它應該提供,因爲它定義了api),primefaces是JSF的實現版本(2.2?)..並且給出的答案是與myfaces相關..這是JSF的其他實現... – khmarbaise 2014-11-01 20:19:22

回答

0

我試圖與JSF 2.2,這個代碼片段:

<h:body onload="init();" onclick="init();" ondblclick="init();" onkeydown="init();" 
     onkeypress="init();" onkeyup="init();" onmousedown="init();" onmousemove="init();" 
     onmouseout="init();" onmouseover="init();" onmouseup="init();" onunload="init();" > 
</h:body> 

這裏是生成的HTML:

<body onload="init();" onunload="init();"></body> 

看來只有onloadonunload事件正在上<h:body>渲染,即使文檔否則:https://myfaces.apache.org/core21/myfaces-impl/tagdoc/h_body.html

編輯:

這裏有一個解決方案,使您<h:body>支持這些事件:Body attributes (onkeydown, onkeyup...) not rendered after upgrading to Primefaces 5.1, from 4.0

+0

這很奇怪,因爲在我的舊項目中(沒有使用maven)它工作得很好...... – 2014-10-31 17:11:55

+0

@MateusViccari See爲解決方案更新答案。 – Thrax 2014-11-07 10:54:15