Continuations can run in embedded elements and any number of them can be active at the same time.
Below is the implementation of a page with multiple counters that all run independently as continuations with while loops.
The Counter.java element:
@Elem(url="", submissions = {
@Submission(name = "decrease"),
@Submission(name = "increase")})
public class Counter extends Element {
public void processElement() {
int counter = 0;
Template t = getHtmlTemplate("counter");
while (true) {
t.setValue("counter", counter);
print(t);
pause();
if (hasSubmission("decrease")) counter--;
if (hasSubmission("increase")) counter++;
}
}
}
The counter.html template that is used by the element above:
<div>
<r:v name="counter"/>
<form action="${v SUBMISSION:FORM:decrease/}" method="post">
<r:v name="SUBMISSION:PARAMS:decrease"/>
<input type="submit" value=" - " />
</form>
<form action="${v SUBMISSION:FORM:increase/}" method="post">
<r:v name="SUBMISSION:PARAMS:increase"/>
<input type="submit" value=" + " />
</form>
</div>
The main template that includes three counters as embedded elements:
<body>
<r:v name="ELEMENT:Counter:1"/>
<br />
<r:v name="ELEMENT:Counter:2"/>
<br />
<r:v name="ELEMENT:Counter:3"/>
</body>
It would help a lot in the examples if they were compilable. Why not add the necessary import statements?
On the other side it is great to have such examples. That is what I appreciate a lot.