We do something like that, but take it a little further. The activate method is static and gets the page from the cycle. So the activate method you posted would look something like this:
public void activate(IRequestCycle cycle, String accountKey) throws ValidationException { AccountEditPage nextPage = (AccountEditPage) cycle.getPage("AccountEditPage"); try { setKey(accountKey); // Access business layer, build page, etc, then activate... cycle.activate(nextPage); } catch (ValidationException e) { throw e; } catch (Exception e) { throw new ApplicationRuntimeException(e); } } Which will simplify your call down to: AccountEditPage.activate(cycle, "accountKey"); On 8/8/05, Geoff Callender <[EMAIL PROTECTED]> wrote: > > Hi, > > Anyone care to comment on a style of activating pages that I've grown to > like? > > Instead of doing it this way - treating the next page as a bean and using > setters, eg. > > public void edit(IRequestCycle cycle) { > Object[] parameters = cycle.getServiceParameters(); > String accountKey = (String) parameters[0]; > > AccountEditPage nextPage = > (AccountEditPage) cycle.getPage("AccountEditPage"); > nextPage.setAccountKey(accountKey); > cycle.activate(cycle); > } > > I've been doing it this way - create an activate method that specifies the > parameters, eg. > > public void edit(IRequestCycle cycle) { > Object[] parameters = cycle.getServiceParameters(); > String accountKey = (String) parameters[0]; > > AccountEditPage nextPage = > (AccountEditPage) cycle.getPage("AccountEditPage"); > nextPage.activate(cycle, accountKey); > } > > The page now has a clear, explicit external interface (called activate!), > and > crisp, unambiguous interfaces are good. To understand the pre-requisites > of any page you need look only at its activate(..) method signature. > > Better still, the signature shows the exceptions thrown, allowing the > caller > to do things like display the error on the same page: > > public void edit(IRequestCycle cycle) { > Object[] parameters = cycle.getServiceParameters(); > String accountKey = (String) parameters[0]; > > try { > AccountEditPage nextPage = > (AccountEditPage) cycle.getPage("AccountEditPage"); > nextPage.activate(cycle, accountKey); > } > catch (ValidationException e) { > setErrorMessage(e.toString()); > } > catch (Exception e) { > throw new ApplicationRuntimeException(e); > } > } > > Here's an example of activate: > > public void activate(IRequestCycle cycle, String accountKey) > throws ValidationException { > > try { > setKey(accountKey); > > // Access business layer, build page, etc, then activate... > > cycle.activate(this); > } > catch (ValidationException e) { > throw e; > } > catch (Exception e) { > throw new ApplicationRuntimeException(e); > } > } > > Any comments? Any limitations I haven't thought of, etc? > > Geoff > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >