On 7/10/2014 3:43 AM, Martin Grigorov wrote:

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.

That makes sense. But that issue can be taken care of easily enough using a precondition:

protected BasePage(final PageParameters parameters, final IModel<?> model)
  {
    super(parameters);
checkArgument(parameters == null || model == null, "Must not provide both parameters and a model.");


There is a very simple workaround for you:

super(parameters);
setDefaultModel(model);
this.myConstant1 = ...
this.myConstant2 = ...

Ah, thanks! I will use that.

Still, it seems a shame to explicitly set the default model (which goes through a lot of change-reporting logic), when we could have provided it to the constructor. I note that even the Page constructor uses the sort of constructor chaining that I want to do:

    protected Page()
    {
        this(null, null);
    }

    protected Page(final IModel<?> model)
    {
        this(null, model);
    }

    protected Page(final PageParameters parameters)
    {
        this(parameters, null);
    }

    private Page(final PageParameters parameters, IModel<?> model)
    {

But because the ultimate constructor is marked private, even WebPage is forced to go through the common-initialization drudgery:

    protected WebPage(final IModel<?> model)
    {
        super(model);
        commonInit();
    }

    etc.

I recommend Wicket modify the Page ultimate constructor to be protected, and add a simple precondition to keep it from being accidentally misused:

  protected Page(final PageParameters parameters, final IModel<?> model)
  {
    super(parameters);
checkArgument(parameters == null || model == null, "Must not provide both parameters and a model.");


Cheers,

Garret

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

Reply via email to