About "Activate"
The traditional approach using
pageBeginRender() is not the only approach. In JumpStart, we use a different convention: every page
provides an activate() method and that is its entry point. The activate() method sets up the things on the page
and then it asks Tapestry to make it active. It is analogous to a constructor.
So what's the difference?
- The activate() method specifies the parameters it needs to set up the page and the exceptions it can throw,
eg. OrderViewPage might declare activate(Long orderId) throws OrderNotFoundException
.
It provides a clear contract to the calling page.
- If the activate() method decides to throw an exception then it will have returned without having
asked Tapestry to make its page active. The calling page still has control, so it could, for instance,
redisplay itself exactly as before plus an error message. In the traditional approach you would have to go to
an error page.
- Using the activate() approach, each page is responsible for its own setup and encapsulation is achieved.
In the traditional approach the lines of responsibility are blurred - the page is more like a java bean
so it's tempting to make the caller do a lot of the setting up of the next page before activating it.
So is pageBeginRender() used at all in JumpStart? Absolutely yes - you will find it wherever we need something
special done every time the page is rendered and/or rewound.