2014-02-19 25 views
0

我使用maven tomcat7:run部署了一個簡單的Primefaces 4 webapp。該webapp包含1個表單。該表單可以無任何錯誤地顯示。當我提交表單,我收到以下錯誤:使用Maven Tomcat7插件時的Primefaces錯誤

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"; 
    } 
} 

回答