This is a long email asking how to do rewinding in Tapestry.
I'm in a situation similar to a Form where I need to do
a rewind. If you know how to do this, please skip down
to the <HELP> section in the java at the end of this
email and tell me what to put there!
If you want the whole story of what's going, read on and
I'll explain why I _think_ I need a rewind.
What we're trying to do:
~~~~~~~~~~~~~~~~~~~~~~~
We have a page that displays an object and a list of subobjects.
All objects are retrieved from a database when the page is
attached and all objects have unique ids.
Each subobject has a boolean value that we want to be able to
toggle from the display page. We display the subobjects in a table
using a Foreach and in each row we put a Direct with a context of
the subobject's id. The Direct is supposed to toggle the boolean
in the subobject and rerender the page.
The problem:
~~~~~~~~~~~
The Direct is not called until after the page is attached so the
objects have been retrieved from the database before the boolean
was updated in the database. So the boolean value for the subobject
that is displayed is stale.
Possible solutions:
~~~~~~~~~~~~~~~~~~
From reading the tapestry docos it seems that the Direct needs to
rewind and rerender the page after it updates the database. I can't
figure out how to do this; are there any simple examples of this
(I find it hard to learn things from VLib since it's so large and
is doing so many things)?
Another option may be to use a ListEdit instead of a Foreach. I get
the impression from the docs that it is supposed to help with this
type of problem. But I can't figure out how to use a ListEdit.
Are there any simple examples using a ListEdit?
Otherwise, I suppose there are workarounds like putting the Direct
in another page and then cycling back to the main page, or sticking
the new boolean value in the visit and using that on the attach instead
of whatever is in the database. But both of these are bad kludges
which I'm desperate to avoid.
Non-working Example:
~~~~~~~~~~~~~~~~~~~
The following java file demonstrates the problem I'm trying to solve.
I use a static boolean to emulate an entry in a database. What I'm
trying to figure out is how to get toggleWithRewind to work.
>>>>>>>>>>>>>>>>>>>>>>
package espial.ds.ttest.rewindtest;
import com.primix.tapestry.*;
public class RewindTest extends BasePage{
boolean m_boolean;
static boolean s_boolean; //this emulates a dynamic value pulled from a database
public RewindTest() {
}
public void attach(IEngine value) {
super.attach(value);
//simulate retrieving the value from the database
setBoolean(s_boolean);
}
public boolean isBoolean() {
return m_boolean;
}
public void setBoolean(boolean aBoolean) {
m_boolean = aBoolean;
}
public void toggle(String[] context, IRequestCycle cycle) {
s_boolean = !isBoolean();
}
public void toggleWithRewind(String[] context, IRequestCycle cycle) {
s_boolean = !isBoolean();
try {
// <HELP thanksInAdvance='true'>
cycle.rewindPage(cycle.getNextActionId(), cycle.getPage().);
// </HELP>
}
catch (RequestCycleException e) {
e.printStackTrace();
// this throws a StaleLinkException,
// "Action id 1 does not match component Home."
// obviously my guess at how to use rewind is off the mark
}
}
public void reload(String[] context, IRequestCycle cycle) {
//the page will re-render without any effort on our part
}
}
