2014-02-05 38 views
0

我有一個關於在JSF中使用el-tag的奇怪問題。我有以下的依賴幾乎是空的項目:目標無法訪問,標識符已解析爲空,並顯示正確的名稱,依賴項,導入

<dependency> 
     <groupId>javax.el</groupId> 
     <artifactId>el-api</artifactId> 
     <version>2.2</version> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.web</groupId> 
     <artifactId>el-impl</artifactId> 
     <version>2.2</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.faces</groupId> 
     <artifactId>jsf-api</artifactId> 
     <version>2.2.4</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.faces</groupId> 
     <artifactId>jsf-impl</artifactId> 
     <version>2.2.4</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
    </dependency> 

    <dependency> 
     <groupId>org.primefaces</groupId> 
     <artifactId>primefaces</artifactId> 
     <version>4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.primefaces.themes</groupId> 
     <artifactId>cupertino</artifactId> 
     <version>1.0.10</version> 
    </dependency> 
    <dependency> 
     <groupId>org.primefaces.themes</groupId> 
     <artifactId>all-themes</artifactId> 
     <version>1.0.10</version> 
    </dependency> 

而且我有一個bean,它開始像這樣:

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.ApplicationScoped; 

@ManagedBean(name = "requester") 
@ApplicationScoped 
public class UserBean implements Serializable { 
    public String getRequestIdentificator() { 
     return requestIdentificator; 
    } 

    public void setRequestIdentificator(String requestIdentificator) { 
     this.requestIdentificator = requestIdentificator; 
    } 

和web.xml看起來是這樣的:

<web-app version="3.0" 
     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_3_0.xsd" 
     id="DAS_ID"> 

    <display-name>DAS</display-name> 

    <context-param> 
     <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name> 
     <param-value>com.sun.el.ExpressionFactoryImpl</param-value> 
    </context-param> 
    <context-param> 
     <param-name>com.sun.faces.expressionFactory</param-name> 
     <param-value>com.sun.el.ExpressionFactoryImpl</param-value> 
    </context-param> 
    <context-param> 
     <description>Parameter required by Mojarra 2.0</description> 
     <param-name>com.sun.faces.allowTextChildren</param-name> 
     <param-value>true</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name> 
     <param-value>true</param-value> 
    </context-param> 

    <context-param> 
     <description> 
      Tell the runtime where we are in the project development 
      lifecycle. Valid values are: 
      Development, UnitTest, SystemTest, or Production. 
      The runtime will display helpful hints to correct common mistakes 
      when the value is Development. 
     </description> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 

    <!-- Faces Servlet --> 
    <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>/faces/*</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file>faces/main.xhtml</welcome-file> 
    </welcome-file-list> 

</web-app> 

不幸的是,每次,像<p:commandButton value="Request" action="#{requester.requestData}" />這樣的東西被稱爲,這個結果

SEVERE: javax.el.PropertyNotFoundException: /main.xhtml @19,100 value="#{requester.requestIdentificator}": Target Unreachable, identifier 'requester' 
resolved to null 

我已經搜索了錯誤,常見的錯誤是例如總結在這裏:Target Unreachable, identifier resolved to null,但沒有一個適用。此外,NetBeans能夠對我所做的每件事都使用代碼完成功能(我也嘗試了除requestIdentificator之外的其他功能) - 因此,代碼似乎寫得完全正確。 Bean接縫永遠不會被初始化(所以在構造函數中的日誌不會被調用),但根據例如https://stackoverflow.com/a/11013290/2096209,沒有必要在JSF 2.x(我使用2.1)中的faces-config中註冊Bean,這樣就不會成爲問題。

我正在使用mvn tomcat7運行一切:運行。有沒有人提示如何解決這個問題?

+0

看起來像你的類'UserBean'沒有這個'requestIdentificator'屬性的getter/setter。檢查您的託管bean定義。 –

+0

只需要注意,這個問題與maven以及web.xml文件都沒有關係...... –

+0

如果同時爲requestIdentififactor提供了getter和setter。感謝提示,我會將它們添加到任務中。我不知道問題出在哪裏,所以我發佈了一些我認爲可能與問題有關係的東西。 –

回答

0

I使用javax.faces.bean軟件包時,經常會遇到同樣的問題。嘗試導入的

import javax.faces.bean.ApplicationScoped; 

代替作爲@ManagedBean註釋使用@Named

import javax.inject.Named; 
import javax.enterprise.context.ApplicationScoped; 

@Named("requester") 
@ApplicationScoped 
public class UserBean implements Serializable { 

然後生成並重新部署

import javax.enterprise.context.ApplicationScoped; 

代替。看看是否有幫助

+0

感謝您的回答,但我想使用JSF而不是CDI,所以@Named對我來說不是正確的方式(我的依賴不適合CDI)。 –

0

問題是,我試着用mvn tomcat7運行它:運行。如果我把這個戰爭複製到一個普通的tomcat7實例中,它就會起作用,而且,如果我使用mvn tomcat7運行它:run-war。似乎是一個maven-tomcat插件的bug。

相關問題