2014-10-31 48 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