I have two buttons in jsp namely Start and 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() **.)
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.
and class FunctionExit is:
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
(ii) making Stop Button's Disabled Property = !Start Button's Disabled Property
the expected behaviour has been achieved.
The code is as follows: