gpt4 book ai didi

java - JSF 错误 "The class ' beans.OperationBean' 没有属性 'operation' 。”

转载 作者:行者123 更新时间:2023-12-02 00:13:38 25 4
gpt4 key购买 nike

我遵循了 getter 和 setter 的所有约定。 numOne 和 numTwo 属性似乎可以工作,但操作和 numsCrunched 属性都不起作用。我只是想创建一个基本的计算器。如果我在 HTML 中编写“OperationBean.operation”,它不会崩溃,但也不会显示任何内容。我觉得我缺少一条重要的信息来成功运行它。

索引.xhtml:

<?xml version='1.0' encoding='UTF8'?>
<!DOCTYPE html PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Number Cruncher</title>
</h:head>
<h:body style="background-color:lightgray">
<f:view>
<h:outputText style="font-size:large; font-family:serif; font-weight:bold;" value="Number Cruncher"></h:outputText>
<hr></hr>
<h:form>
<h:panelGrid columns="2" >
<h:outputText value="Number One:"></h:outputText>
<h:inputText id="numOne" value="#{operationBean.numOne}"></h:inputText>
<h:outputText value="Number Two:"></h:outputText>
<h:inputText id="numTwo" value="#{operationBean.numTwo}"></h:inputText>
</h:panelGrid>
<hr></hr>
<h:commandButton value="Add"
action="#{operationBean.operationAdd}"></h:commandButton>
<h:commandButton value="Subtract"
action="#{operationBean.operationSubtract}"></h:commandButton>
<h:commandButton value="Divide"
action="#{operationBean.operationDivide}"></h:commandButton>
<h:commandButton value="Multiply"
action="#{operationBean.operationMultiply}"></h:commandButton>
<h:commandButton value="Crunch: #{operationBean.operation}"
action="#{operationBean.crunch}"></h:commandButton>
</h:form>
</f:view>
</h:body>
</html>

OperationBean.java:

package beans;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
@Named(value = "operationBean")
@SessionScoped
public class OperationBean implements Serializable {
private double numOne;
private double numTwo;
private double numsCrunched;
private String operation;


/**
* Creates a new instance of OperationBean
*/
public OperationBean() {
//this.operation = "+";
}

public void operationAdd(){
this.operation = "+";
}
public void operationSubtract(){
this.operation = "-";
}
public void operationDivide(){
this.operation = "/";
}
public void operationMultiply(){
this.operation = "*";
}

/**
* @return the operation
*/
public String getOperation(){
return operation;
}

/**
* @return the answer
*/
public double getNumsCrunched(){
return numsCrunched;
}
/**
* @return the numOne
*/
public double getNumOne() {
return numOne;
}

/**
* @param numOne the first number to set
*/
public void setNumOne(double numOne) {
this.numOne = numOne;
}

/**
* @return the numTwo
*/
public double getNumTwo() {
return numTwo;
}

/**
* @param numTwo the second number to set
*/
public void setNumTwo(double numTwo) {
this.numTwo = numTwo;
}


public void setNumsCrunched(double numsCrunched){
this.numsCrunched = numsCrunched;
}

public double crunch() {
/*
switch (operation) {
case '+':
setAnswer(this.numOne + this.numTwo);
//return this.answer;
case '-':
setAnswer(this.numOne - this.numTwo);
//return this.answer;
case '/':
setAnswer(this.numOne / this.numTwo);
//return this.answer;
case '*':
setAnswer(this.numOne * this.numTwo);
//return this.answer;
default:
break;
}*/
if("+".equals(this.operation)){
this.numsCrunched = this.numOne + this.numTwo;
}else{
this.numsCrunched = this.numOne - this.numTwo;
}
return 0;
}
}

不幸的是,我不断收到以下错误:

javax.servlet.ServletException: /index.xhtml @30,50 value="Crunch: #{operationBean.operation}": The class 'beans.OperationBean' does not have the property 'operation'.

最佳答案

只需要清理、重建和重新部署服务器。奇怪的错误。

关于java - JSF 错误 "The class ' beans.OperationBean' 没有属性 'operation' 。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58104415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com