将@ManagedBean切换为@Named之后:javax.el.PropertyNotFoundException:无法到达目标,标识符"person"解析为null [英] After switching @ManagedBean to @Named: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'person' resolved to null

查看:118
本文介绍了将@ManagedBean切换为@Named之后:javax.el.PropertyNotFoundException:无法到达目标,标识符"person"解析为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是测试这个JSF页面,所以我没有在<h:commandButton/>中设置action属性.这是一个非常简单的表单,带有3个用于输入名字,姓氏和电子邮件的输入框,以及一个名为保存"的按钮.每次单击该按钮,都会收到此错误

I am just testing out this JSF page, so I don't set the action attribute in the <h:commandButton/>. This is a very simple form with 3 input boxes for First Name, Last Name, and Email, and one button called Save. Every time I click that button, I receive this error

javax.el.PropertyNotFoundException: /index.xhtml @19,106 value="#{person.firstName}": Target Unreachable, identifier 'person' resolved to null

但是如果我对JavaBean @ManagedBean进行注释,那么表单就可以顺利通过,但是每次我切换回使用@Named Bean时,我都会再次收到该错误.我尝试了一些在此站点上找到的建议,例如重新启动服务器,检查吸气剂的存在,但这些建议没有帮助.

but if I annotate my JavaBean @ManagedBean, then the form go through just fine, but every time I switch back to using @Named Bean, I receive that error again. I have tried some of the suggestions I found on this site such as restarting the server, checking the presence of the getters, but those did not help.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <meta charset="UTF-8" />
        <title>Simple Form Created Using Facelets</title>
    </h:head>

    <h:body>
        <h:messages/>
        <h:form>
            <h:panelGrid columns="2" columnClasses="rightColumn, leftColumn">

                <h:outputLabel for="firstName" value="First Name:" />
                <h:inputText id="firstName" value="#{person.firstName}"
                             label="First Name"/>

                <h:outputLabel for="lastName" value="Last Name:" />
                <h:inputText id="lastName" value="#{person.lastName}" label="Last Name"/>

                <h:outputLabel for="email" value="Email:"/>
                <h:inputText id="email" value="#{person.email}" label="Email" />

                <h:panelGroup />
                <h:commandButton value="Submit"/>
            </h:panelGrid>
        </h:form>
    </h:body>
</html>

这是我的JavaBean类

This is my JavaBean class

import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class Person {

    private String firstName = "empty";
    private String lastName = "empty";
    private String email = "empty";

    public void Person() {}

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}

这是web.xml文件.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

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

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

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

推荐答案

这是对我的问题

This is the best answer to my problem LINK . Also, cdi-1.2 jar file is not available in GS 4.1 for some reason, that is why the package javax.enterprise.* was not present in my Netbeans, I had to manually download that jar from http://cdi-spec.org/. Now everything works fine including DI. And I did not have to create any configuration files to get it to work either.

这篇关于将@ManagedBean切换为@Named之后:javax.el.PropertyNotFoundException:无法到达目标,标识符"person"解析为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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