Hi, On Thu, Jul 10, 2014 at 12:54 AM, Garret Wilson <gar...@globalmentor.com> wrote:
> Everyone, > > Let's say I want to make a base page, extending WebPage. I want to make it > flexible so that subpages may initialize either using a model or page > parameters. So I try to do this: > > protected BasePage() > { > this(null, null); > } > > protected BasePage(final IModel<?> model) > { > this(null, model); > } > > protected BasePage(final PageParameters parameters) > { > this(parameters, null); > } > > private BasePage(final PageParameters parameters, IModel<?> model) > { > super(null, model); > //initialize stuff here > I think org.apache.wicket.Page#Page(org.apache.wicket.request.mapper.parameter.PageParameters, org.apache.wicket.model.IModel<?>) is private to make it explicit that a page with PageParameters is bookmarkable and possibly stateless, and a Page with IModel is not bookmarkable and stateful. There is a very simple workaround for you: super(parameters); setDefaultModel(model); this.myConstant1 = ... this.myConstant2 = ... > > Obviously I can't do this, because several of the WebPage (and ancestor) > constructors are marked private. I'm forced to do this: > > protected BasePage() > { > super(); > //initialize stuff here > } > > protected BasePage(final IModel<?> model) > { > super(model); > //initialize stuff here > } > > protected BasePage(final PageParameters parameters) > { > super(parameters); > //initialize stuff here > } > > private BasePage(final PageParameters parameters, IModel<?> model) > { > super(parameters, model); > //initialize stuff here > > Look at all the duplicated initialization code! Sure, I could create a > local initialize() method that each of the methods delegate to, but not > only is that ugly it prevents me from making my class variables final > (because final variable must be initialized in the constructor). > > Couldn't the parent classes be a little more lenient, allowing access to > all the constructors, making child classes meant to be base pages more > elegant? > > Garret > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >