问题描述
我使用jsf和icefaces,遇到问题,按钮上的操作不起作用。这是代码: main.xhtml
<?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"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<head>
<title>MainPage</title>
<link rel="stylesheet" href="css/graphic.css"/>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="graphic">
<ui:include src="pages/graphic.xhtml" />
</div>
<div class="form">
<ui:include src="pages/form.xhtml"/>
</div>
<h:link outcome="starter">Go to starter page</h:link>
</body>
</html>
form.xtml
<?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:ace="http://www.icefaces.org/icefaces/components" xml:lang="en"
lang="en"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<div class="x-value">
<p>Выберите X:</p>
<h:form id="x">
<h:selectOneRadio value="#{data.x}" >
<f:selectItem itemValue="-5" itemLabel="-5"/>
<f:selectItem itemValue="-4" itemLabel="-4"/>
<f:selectItem itemValue="-3" itemLabel="-3"/>
<f:selectItem itemValue="-2" itemLabel="-2"/>
<f:selectItem itemValue="-1" itemLabel="-1"/>
<f:selectItem itemValue="0" itemLabel="0"/>
<f:selectItem itemValue="1" itemLabel="1"/>
<f:selectItem itemValue="2" itemLabel="2"/>
<f:selectItem itemValue="3" itemLabel="3"/>
</h:selectOneRadio>
</h:form>
</div>
<div class="y-value">
<p>Выберите Y:</p>
<h:inputText id="y" name="y" value="#{data.y}" a:placeholder="Value in [-3..5]"
converterMessage="Y must be number..."
validatorMessage="Y must be number between -3 and 5 inclusive"
required="true" requiredMessage="Y is required" maxlength="6">
<f:validateDoubleRange minimum="-3" maximum="5"/>
</h:inputText>
</div>
<!--Todo: fix slider [IT IS JUST NOT SHOWING ON THE PAGE]-->
<div class="r-value">
<p>Выберите R:</p>
<h:form>
<ace:sliderEntry value="#{data.r}" />
</h:form>
</div>
<div>
<h:commandButton type="submit" value="Submit" action="#{data.submit}"/>
</div>
</html>
MainBean.java
import lombok.Getter;
import lombok.Setter;
import javax.faces.annotation.ManagedProperty;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import java.io.Serializable;
import java.util.ArrayList;
@ManagedBean(name = "data",eager = true)
@ApplicationScoped
@Getter
@Setter
public class MainBean implements Serializable {
double x = 0;
double y = 0;
double r = 1;
ArrayList<Double> List = new ArrayList();
@ManagedProperty(value = "#{DbBean}")
DB db;
public void submit() {
System.out.println("==============================");
List.add(x);
System.out.println(List);
db.pushInDB(x,y,r,getResult());
}
public boolean getResult() {
return сheckSquare(x,r) || сheckQuarterCircle(x,r) || сheckTriangle(x,r);
}
private boolean сheckSquare(double x,double y,double r) {
return x >= -r && x <= 0 && y >= 0 && y <= r / 2;
}
private boolean сheckQuarterCircle(double x,double r) {
return (x <= 0) && (y <= 0) && ((x * x + y * y) <= r * r);
}
private boolean сheckTriangle(double x,double r) {
return x >= 0 && x <= r && y >= 0 && y <= r / 2 && (y <= -x / 2 + r / 2);
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getR() {
return r;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setR(int r) {
this.r = r;
}
}
这应该输出到控制台:
<h:commandButton value="Submit" action="#{data.submit}"/>
我也尝试以其他方式(例如通过
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)