Em Thu, 18 Jun 2009 20:22:53 -0300, Piero Sartini <li...@pierosartini.de> escreveu:

If I overwrite the onActivate() method and put my code there, this code that needs to be executed on every page gets overwritten as well (and I have to duplicate it on every page). One solution would be to create an initialize() method that needs to be called by every page at the end of their onActivate(). But I hoped for a cleaner
solution :-)

As far as I can see, this is not a matter of Tapestry events, but of implementing a Template design pattern. ;)

abstract class BasePage() {

        @Property private String statusmessage;

        protected abstract User getUser();

        final Object onActivate(EventContext context) {
                ...
                initialize(context);
                ...
        }

        protected void initialize(EventContext context) {
                this.statusmessage = getUser().getStatusMessage();
        }

}

class MyPage() extends BasePage {
        private User user;
        public void initialize(EventContext context) {
                user = repository.findByUsername(context.get(String.class, 0));
        }

        protected User getUser() {
                return user;
        }
}

--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to