我正在使用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";
}
}
答案 0 :(得分:2)
前段时间我遇到过这个问题:Target unreachable, Identifier resolved to null with correct names, dependencys, imports。
对我来说,它可以使用mvn tomat7:run-war
代替mvn tomcat7:run
。但我仍然不知道天气这是插件的错误或特征......