【问题标题】:Primefaces Error when Using Maven Tomcat7 Plugin使用 Maven Tomcat7 插件时出现 Primefaces 错误
【发布时间】:2014-03-20 13:42:06
【问题描述】:

我正在使用 maven tomcat7:run 部署一个简单的 Primefaces 4 webapp。 webapp 包含 1 个表单。表格可以显示没有任何错误。当我提交表单时,我收到以下错误:

Feb 19, 2014 11:52:01 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNING: /registrationWithVal.xhtml @23,117 value="#{userController.registrationUser.userName}": Target Unreachable, identifier 'userController' resolved to null
javax.el.PropertyNotFoundException: /registrationWithVal.xhtml @23,117 value="#{userController.registrationUser.userName}": Target Unreachable, identifier 'userController' resolved to null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:124)

但代码在独立的 Tomcat 7 服务器上运行良好! I guess, there is an issue about maven tomcat7 plugin.从maven tomcat7收到这个错误应该是什么原因。以下是代码摘要:

pom.xml

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>${jsf.version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>${jsf.version}</version>
    </dependency>

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>${primefaces.version}</version>
    </dependency>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
            <plugin>
        </plugins>
    </build>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <description>PrimeFaces Beginners Guide : Chapter 01 </description>

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

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>

registrationWithVal.xhtml

<ui:composition 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:p="http://primefaces.org/ui"
    template="/templates/masterTemplate.xhtml"> 

<ui:define name="bodyContent">

    <h:form id="registrationForm">
        <p:panel header="Registration Form" >
        <p:messages />
        <h:panelGrid columns="3">
            <p:outputLabel value="UserName:*"/>
            <p:inputText id="userName" value="#{userController.registrationUser.userName}" required="true" label="UserName" >
                <p:ajax event="keyup"  update="userNameMsg"/>
            </p:inputText>
            <p:message id="userNameMsg" for="userName"/>

            <p:outputLabel value=""/>
            <p:commandButton action="#{userController.doRegister}" value="Register" update="registrationForm"/>
            <p:outputLabel value=""/>

        </h:panelGrid>
        </p:panel>
    </h:form>

</ui:define>
</ui:composition>

UserController.java

@ManagedBean
@RequestScoped
public class UserController {

    private User registrationUser = new User();

    public UserController() {
    }

    public User getRegistrationUser() {return registrationUser;}

    public void setRegistrationUser(User registrationUser) {this.registrationUser = registrationUser;}

    public String doRegister() {
        String msg = "User Registered Successfully";
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg));
        FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
        return "registrationWithVal.jsf?faces-redirect=true";   
    }
}

【问题讨论】:

    标签: maven jsf-2 primefaces tomcat7


    【解决方案1】:

    我前段时间遇到过这个问题:Target unreachable, Identifier resolved to null with correct names, dependencys, imports

    对我来说,使用 mvn tomat7:run-war 而不是 mvn tomcat7:run 很有效。但我仍然不知道这是一个错误还是插件的一个功能......

    【讨论】:

    • 这对我有用。当运行 tomcat7:run-war 时,所有托管 bean 的信息都列在 tomcat 日志中,而仅使用 tomcat7:run 时不会发生
    猜你喜欢
    • 2014-07-16
    • 1970-01-01
    • 2015-03-28
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 2013-04-07
    • 1970-01-01
    相关资源
    最近更新 更多