目标无法访问,标识符解析为空,并带有正确的名称,依赖项和导入 [英] Target unreachable, Identifier resolved to null with correct names, dependencys, imports

查看:106
本文介绍了目标无法访问,标识符解析为空,并带有正确的名称,依赖项和导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于在JSF中使用el-tag,我遇到了一个奇怪的问题.我有一个几乎为空的项目,具有以下依赖项:

I've got a strange issue concerning the usage of an el-tag in JSF. I have an nearly empty project with the following dependencies:

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

我有一个像这样开始的豆子:

And I have an bean, which starts like this:

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看起来像这样:

and web.xml looks like this:

<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}" />之类的东西,都会导致

Unfortunately, everytime, something like <p:commandButton value="Request" action="#{requester.requestData}" /> is called, this results in

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

我已经搜索过错误,常见错误例如在此处汇总:目标无法访问,标识符解析为空,但这都不适用.此外,NetBeans能够对我正在做的所有事情使用代码完成功能(我也用requestIdentificator进行了其他尝试)-这样看来代码编写完全正确. Bean接缝永远不会初始化(因此不会调用构造函数中的日志记录),而是根据例如 https://stackoverflow.com/a/11013290/2096209 ,不需要在faces-config中注册Bean在JSF 2.x(我使用的是2.1)中,所以不会成为问题.

I already searched for errors, the common errors are e.g. summarized here: Target Unreachable, identifier resolved to null, but none of this applies. Furthermore, NetBeans is able to use code-completion for everything I am doing (I also tried it with other things than requestIdentificator) - so it seems like code is written fully correct. The Bean seams never to be initialized (so the logging in the constructor is not called), but according to e.g. https://stackoverflow.com/a/11013290/2096209, is is not necessary to register the Bean in faces-config in JSF 2.x (I am using 2.1), so that can not be the problem.

我正在使用mvn tomcat7:run运行所有程序.有没有人提示如何解决这个问题?

I am running everything with mvn tomcat7:run. Has anybody an hint how to solve this?

推荐答案

问题是我尝试使用mvn tomcat7:run运行它.如果将war复制到普通的tomcat7实例中,则它也可以工作,并且如果我使用mvn tomcat7:run-war运行它,也可以.似乎是一个maven-tomcat-plugin错误.

The problem was that I tried running it with mvn tomcat7:run. If I copy the war into a normal tomcat7-instance, it works, and as well, if I run it with mvn tomcat7:run-war. Seems to be an maven-tomcat-plugin bug.

这篇关于目标无法访问,标识符解析为空,并带有正确的名称,依赖项和导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆