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]

Reply via email to