Hi Alvin,
Alvin Townsend wrote:
In my Click 1.5 app, I have centralized navigation in a template Page
class. Some of the links are ActionLinks which do stuff (like cleanup
state) and then forward. The problem I'm having is that if a user is
on a given page and then they click the link for the same page in the
navigation, it looks like they are forwarded ad infinitum to the same
page until Click craps out.
Any way to avoid this without dropping the use of the ActionLinks?
If you forward from PageA to PageA you'll need to add a guard against
infinite forwards.
I assume your forward logic is in the Page#onGet method? One way to
resolve this is to register listeners for the ActionLinks and add the
forward logic in the listener instead of #onGet. The way Click handles
forwarding is that the Page Click is forwarding to, is not processed.
In other words Click does not execute the onProcess phase for the
forwarded Page. You can take advantage of this fact by moving your
forward logic to the listener, which won't be invoked a second time on
the forwarded Page.
However you would have to register listeners for every ActionLink.
An alternative (which is probably easier) is to add guard logic in
your onGet method:
public void onGet() {
Context context = getContext();
if (context.getRequestAttribute("forwardGuard") == null) {
context.setRequestAttribute("forwardGuard", Boolean.TRUE);
setForward(getTarget());
}
}
Here you register a request attribute that will guard against
execution the forward a second time.
Does this help?
kind regards
bob