Tapestry 5: how to get the referring page class?

tapestry

Solution

I think there is no predefined method to get the page which rendered the link. The only one you can easily identify is when the page calls itself (for example because of a eventlink, which triggers an event and then forwards to the page itself).

Depending on your situation you may choose a different solution. There is no single best answer. This might help: Passing Data Between Pages

- A @SessionState object which stores the last page is easy, but it probably screws up if the user opens multiple windows/tabs or uses forward/back in his browser.

- An activation context which contains the pagename is easy too, but the user could mess with the parameters.

.

Where you want to setup/reset your properties also depends on what you are doing: What is called when I normally use the onActivate() method, but this method is also called twice when an EventLink or Submit is triggered!

Problem

Is there a way to get the Tapestry page class or name of the previous page that generated the request to the current page? I have a `@Persist` property in a Tapestry page that has to be reset unless the referring page is the current page or a predefined set of other Tapestry pages. Does Tapestry provide a clean way to access the class or name of the 'referrer' page, without having to look manually into the Request object? And given that I manage to somehow get the the class/name of the referring page, where would be the best place to conditionally reset the `@Persist`-ed properties? `SetupRender()` or `OnActivate()`?

Original source