javax.el.PropertyNotFoundException:/index.xhtml @ 23,97 action =“#{execise04.getInput}”:目标无法访问,标识符'execise04'已解析为null

时间:2018-04-26 00:01:57

标签: jsf

我一直遇到同样的问题。目前我正在收到错误 javax.el.PropertyNotFoundException:/index.xhtml @ 23,97 action =“#{execise04.getInput}”:目标无法访问,标识符'execise04'已解析为null

我不完全确定我在做错的是代码。我看过他们说的解决了我的问题的另一篇文章并没有解决我的问题,我不明白它的说法。它并没有真正给出解决方案只是让我转过身来。此外,我还有其他问题,例如在我得到不同的错误之前按下按钮,它不会打开应该显示输出的第二个窗口。有人请帮忙。我已经被困在这几天了,它变得令人难以置信的沮丧。

<?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">
    <h:head>
        <title>Exercise04</title>
    </h:head>
    <h:body>
        <h:form>
            <center>
                <h3>
                    Compute Loan Payment
                </h3>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Loan Amount"/>
                    <h:inputText id="amount" value="#{exercise04.loanAmount}"/>
                    <h:outputLabel value="Annual Interest Rate"/>
                    <h:inputText id="rate" value="#{exercise04.annualInterestRate}"/>
                    <h:outputLabel value="Number Of Years"/>
                    <h:inputText id="years" value="#{exercise04.numberOfYears}"/>
                </h:panelGrid>
                <br />
                <h:commandButton value="Compute Loan Payment" action = "#{execise04.getInput}"/>
            </center>
        </h:form>
    </h:body>
</html>

<?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://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Exercise02</title>
    </h:head>
    <h:body>
        <center>
            <h:outputText escape="false" value="{exercise02.table}" />
        </center>
    </h:body>
</html>



    import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "exercise04")
@SessionScoped
public class Exercise04 implements Serializable {
    private double annualInterestRate;
    private int numberOfYears;
    private double loanAmount;
    private java.util.Date loanDate;
public Exercise04() {
    this(10, 1, 1000);
}

public Exercise04(double annualInterestRate, int numberOfYears, double loanAmount) {
    this.annualInterestRate = annualInterestRate;
    this.numberOfYears = numberOfYears;
    this.loanAmount = loanAmount;
    loanDate = new java.util.Date();
}

public double getAnnualInterestRate() {
    return annualInterestRate;
}

public void setAnnualInterestRate(double annualInterestRate) {
    this.annualInterestRate = annualInterestRate;
}

public int getNumberOfYears() {
    return numberOfYears;
}

public void setNumberOfYears(int numberOfYears) {
    this.numberOfYears = numberOfYears;
}

public double getLoanAmount() {
    return loanAmount;
}

public void setLoanAmount(double loanAmount) {
    this.loanAmount = loanAmount;
}

public double getMonthlyPayment() {
    double monthlyInterestRate = annualInterestRate / 1200;
    double monthlyPayment = loanAmount * monthlyInterestRate / (1
            - (1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12)));
    return monthlyPayment;
}

public double getTotalPayment() {
    double totalPayment = getMonthlyPayment() * numberOfYears * 12;
    return totalPayment;
}

public java.util.Date getLoanDate() {
    return loanDate;
}

public String getInput() {
    return "<p style=\"color:red\"><br />"
    + "Loan Amount: " + loanAmount + "<br />"
    + "Annual Interest Rate: " + annualInterestRate + "<br />"
    + "Number Of Years: " + numberOfYears + "<br />"
    + "Monthly Payment: " + getMonthlyPayment() + "<br />"
    + "Total Payment: " + getTotalPayment() + "</p>";
}

}

1 个答案:

答案 0 :(得分:0)

您正在将CDI与JSF注释混合使用。 @ManagedBean和@RequestScoped(使用此包)是JSF注释。 @Named是一个CDI注释。如果要使用CDI删除@ManagedBean并将@RequestScoped包更改为javax.enterprise.context。如果您不想使用CDI(我不建议这样做,因为这些注释已被弃用),请删除@Named注释并将name属性添加到@ManagedBean注释。