Hi Howard,

At the moment the way to make one page transfer to another (e.g. in a Direct listener) is by setting the page that will render the response in the cycle:

cycle.setPage(page);

One drawback of this approach is that the page is not notified that it has become "active" until it receives the beginResponse() call and at that time it may be too late to do some actions (e.g. initialize and redirect to another page if the initialization fails)

Another issue that seems to pop up occasionally on this list is that setPage() does not invoke validate (it is a relatively low level call in a sense) and hence it allows some pages to be accessed even though their validate() would normally fail, and to avoid that, people have to call and handle validate() manually.

One approach to resolve these issues that we use here locally is to add the method activate() to the pages and invoke it instead of calling setPage():

page.activate(cycle);

A possible implementation could be something like this:

public void activate(IRequestCycle cycle) throws RequestCycleException
{
try {
this.validate(cycle);
cycle.setPage(this);
}
catch (PageRedirectException e) {
IPage page = cycle.getPage(e.getTargetPageName());
page.activate(cycle);
}
}

In this way a "notification" is sent that tells the page "you will be the one that will render the response" and allows it to take some action about it. In a sense, it also follows the OO maxima "ask the object to do the action, rather than doing it yourself".

Timewise, this notification fills the gap between attach() that says that the page is attached to an engine/cycle (but it will not necessarily do the rendering) and beginResponse() that says that the rendering is to start and the rendering page can no longer be changed.

This approach is backward-compatible, since one can still use cycle.setPage() (and older code would not need to be changed).

Of course, variations of the approach are possible, e.g. setPage() could invoke activate() by itself, etc.

What do you think about this? Does it make sense to make it a part of the framework (it probably means another method in IPage, though), or it should be left to the developers as a custom solution?

best regards,

-mb

 



Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site

Reply via email to