[英]Interfere one function from another function in java
I have two buttons in jsp namely Start and Stop. 我在jsp中有两个按钮,分别是Start和Stop。
Expected: Only Once Start button should be clicked, counting should start, and counting should be stopped when Stop Button is pressed. 预期:仅应单击一次“开始”按钮,才应开始计数,并且在按下“停止”按钮时应停止计数。
(With reference to the code, When Stop button is pressed function stop_action() should be called, boolean stopOperation set to true and **while iteration should stop in start_action() **.) (参考该代码,当按下“ 停止”按钮时,应调用stop_action()函数,将boolean stopOperation设置为true,而**则应在start_action()中停止迭代。)
Actual: Whenever the Start button is Clicked, new counting is started. 实际:只要单击“开始”按钮,就会开始新的计数。 Counting could not be stopped even pressing Stop Button many times. 即使多次按停止按钮也无法停止计数。
The code is as follows: 代码如下:
In faces-config.xml, FunctionExit (class, abcwar.FunctionExit) has request scope. 在faces-config.xml中, FunctionExit(类,abcwar.FunctionExit)具有请求范围。
and class FunctionExit is: 而FunctionExit类是:
package abcwar;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import javax.faces.FacesException;
public class FunctionExit extends AbstractPageBean {
private boolean stopOperation = false;
private void _init() throws Exception {
}
public FunctionExit() {
}
@Override
public void init() {
try {
_init();
} catch (Exception e) {
log("FunctionExit Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
}
@Override
public void preprocess() {
}
@Override
public void prerender() {
}
@Override
public void destroy() {
}
public String stop_action() {
setStopOperation(true);
System.out.println("getStopOperation() :" + getStopOperation());
return "true";
}
public String start_action() {
long steps = 0;
while (!getStopOperation()) {
steps++;
System.out.println("Step Count :" + steps + ", getStopOperation() :" + getStopOperation());
}
return null;
}
public boolean getStopOperation() {
return stopOperation;
}
public void setStopOperation(boolean stopOperation) {
this.stopOperation = stopOperation;
}
}
After 后
(i) defining the functions start_action(), stop_action() and class variable boolean stopOperation in Session Scoped Class, SessionBean1 (i)在Session Scoped类SessionBean1中定义函数start_action(),stop_action()和类变量boolean stopOperation
(ii) making Stop Button's Disabled Property = !Start Button's Disabled Property (ii)使“停止按钮”的“禁用”属性=!“开始”按钮的“禁用”属性
the expected behaviour has been achieved. 已达到预期的行为。
The code is as follows: 代码如下:
package abcwar;
import com.sun.rave.web.ui.appbase.AbstractSessionBean;
import javax.faces.FacesException;
public class SessionBean1 extends AbstractSessionBean {
private boolean stopOperation = false;
private long steps = 0;
private void _init() throws Exception {
}
public SessionBean1() {
}
@Override
public void init() {
try {
_init();
} catch (Exception e) {
log("SessionBean1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
}
}
@Override
public void passivate() {
}
@Override
public void activate() {
}
@Override
public void destroy() {
}
protected ApplicationBean1 getApplicationBean1() {
return (ApplicationBean1) getBean("ApplicationBean1");
}
public boolean isStopOperation() {
return stopOperation;
}
public void setStopOperation(boolean stopOperation) {
this.stopOperation = stopOperation;
}
public String stop_action() {
setStopOperation(true);
System.out.println("getStopOperation() :" + isStopOperation());
return null;
}
public String start_action() {
if (steps <= 0) {
steps = 0;
}
setStopOperation(false);
while (!isStopOperation()) {
steps++;
System.out.println("Step Count :" + steps + ", getStopOperation() :" + isStopOperation());
}
return null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.