jsf 目标无法访问,标识符 [bean] 解析为 null

标签 jsf el propertynotfoundexception

<分区>

通过以下链接挖掘后,我无法解决问题:Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable

我收到以下错误:javax.servlet.ServletException:/Project9.xhtml @13,55 value="#{ProjectBean.income}": Target Unreachable, identifier [ProjectBean] resolved to null

我的表格:

<!DOCTYPE html>
 <html xmlns="http://wwww3.org/1999/xhtml"
  xmlns:a="http://xmlns.jcp.org/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  >
<h:head>
<title>Project9</title>
</h:head>

<h:body>
<h:form>
    Income: <h:inputText value="#{ProjectBean.income}"/>
    Number of people: <h:inputText value="#{ProjectBean.numPeople}"/>
        <h:commandButton value= "Submit" action= "Project9response"/>
</h:form>

</h:body>
</html>

我不确定正确的约定是 wwww3.org 还是 www.3.org,但我都试过了。

我的回复页面:

<!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:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  >
<h:head>
<title><ui:insert name="title">Project 9 response</ui:insert></title>
</h:head>


<h:body>
Am I above the poverty level: #{ProjectBean.abovePovertyLevel()}

</h:body>

</html>

我的 bean :

@ManagedBean
@SessionScoped
public class ProjectBean implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private double income;
private double numPeople;

//constructor is no arg
public ProjectBean() {

}

public double getIncome() {
    return income;
}
public void setIncome(double income) {
    this.income = income;
}
public double getNumPeople() {
    return numPeople;
}
public void setNumPeople(double numPeople) {
    this.numPeople = numPeople;
}

public boolean abovePovertyLevel() {
    if ( income < (16460.00 + 4320.00) * (numPeople - 2)){
        return false;
    }
    else {
    return true;
}
}

}

我的 faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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-facesconfig_2_3.xsd"
version="2.3">

</faces-config>

我在 WEB-INF 的 lib 文件夹中有我的 faces-config.xml 和我的 javax-faces.2.2.8.jar 文件 我的bean在Java Resources的src文件夹中

我有另一个名为 helloworld 的项目,其中有几个可以正常工作的小 JSF 项目,我尝试将 project9 复制到 helloworld 并运行它,但我只在该项目上遇到相同的错误

我已经尝试按照人们的建议清理我的项目

这是一个学生项目,也是我对 JSF 和 Tomcat 的第一次介绍。我正在使用 Mac 和 Eclipse 光子。

正如我在代码中的评论中所述,如果我尝试绕过响应 xhtml 文件并直接进入我的 html 表单中的 javabean 方法,我会在 ProjectBean.abovePovertyLevel() 下看到一条下划线和错误“the action值与导航案例结果不匹配”

我不确定上面链接中关于 CDI 等的一些答案,目前我无法理解。

最佳答案

没关系,我刚刚解决了这个问题 在我的注释中添加了一个名称:@ManagedBean(name="ProjectBean")

我也意识到,如果不先公布贫困线,我的方法是错误的

int povertyLevel = (16460 + 4230 * (numPeople-2));
    if(income > povertyLevel)
        return true;
    else{
    return false;
    }

这似乎有效

关于jsf 目标无法访问,标识符 [bean] 解析为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53698227/

相关文章:

java - Spring Roo 是适合我的工具吗? (见帖子中的要求列表)

jsp - 在JSP中添加外部资源(CSS/JavaScript/图像等)

jsf - 识别和解决javax.el.PropertyNotFoundException:目标不可达

jsf - 识别和解决javax.el.PropertyNotFoundException:目标不可达

jsf - p :dialog appears on bottom when p:blockUI targets it

java - 特立尼达 2.0 是否已被取代或废弃?

jsf - 是 PrimeFaces Javascript 库的 API(即 : widgetVars) available and documented?

eclipse - 如何在Eclipse中修改EL打开模板?

java - 比较表达式语言中的字符串和 boolean 值

hibernate - javax.el.PropertyNotFoundException : Property not found on type org. hibernate.collection.internal.PersistentSet