在JSF上没有呈现的方法(onkeydown,onkeyup ...)

时间:2014-10-31 11:56:12

标签: java maven jsf

我正在将非maven webapp项目迁移到maven,我遇到了一些问题。 我在我的页面中:

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

但是在浏览器中渲染html后我才看到:

<body>...</body>

出于某种原因它取出了身体方法......什么能引起这种奇怪的行为?

更新

我在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>

更新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>

也许其中一些依赖项是错误的,但哪一个?

1 个答案:

答案 0 :(得分: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