Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/210#discussion_r99945295
  
    --- Diff: 
wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageProvider.java
 ---
    @@ -388,49 +350,95 @@ public Integer getRenderCount()
                return renderCount;
        }
     
    -   /**
    -    * Checks whether or not the provider has a page instance. This page 
instance might have been
    -    * passed to this page provider directly or it may have been 
instantiated or retrieved from the
    -    * page store.
    -    * 
    -    * @return {@code true} iff page instance has been created or retrieved
    -    */
        @Override
    -   public final boolean hasPageInstance()
    +   public String toString()
        {
    -           if (pageInstance == null && pageId != null)
    -           {
    -                   // attempt to load a stored page instance from the page 
store
    -                   getStoredPage(pageId);
    -           }
    -           return pageInstance != null;
    +           return "PageProvider{" + "renderCount=" + renderCount + ", 
pageId=" + pageId
    +                   + ", pageClass=" + pageClass + ", pageParameters=" + 
pageParameters + '}';
        }
     
        /**
    -    * Returns whether or not the page instance held by this provider has 
been instantiated by the
    -    * provider.
    +    * A provision is the work necessary to provide a page. It includes to 
resolve parameters to a
    +    * page, to track the resolution metadata and to keep a reference of 
the resolved page.
         * 
    -    * @throws IllegalStateException
    -    *             if this method is called and the provider does not yet 
have a page instance, ie
    -    *             if {@link #getPageInstance()} has never been called on 
this provider
    -    * @return {@code true} iff the page instance held by this provider was 
instantiated by the
    -    *         provider
    +    * The logic based on {@link PageProvider}'s parameters:
    +    * 
    +    * - having an stored page id, the stored page is provided
    +    * 
    +    * - having only a page class, a new instance of it is provided
    +    * 
    +    * - having non stored page id plus page class, a new instance of the 
page class is provided
    +    * 
    +    * - having non stored page id and no page class, no page is provided
    +    * 
    +    * - being a page instance, the instance itself will be the provided 
page
    +    *
    +    * @author pedro
         */
    -   @Override
    -   public final boolean isPageInstanceFresh()
    +   private class Provision
        {
    -           if (!hasPageInstance())
    +           transient IRequestablePage page;
    +           boolean failedToFindStoredPage;
    +
    +           IRequestablePage getPage()
                {
    -                   throw new IllegalStateException("Page instance not yet 
resolved");
    +                   if (page == null && doesProvideNewPage())
    +
    +                           page = 
getPageSource().newPageInstance(pageClass, pageParameters);
    +
    +                   return page;
    +           }
    +
    +           boolean didResolveToPage()
    +           {
    +                   return page != null;
    +           }
    +
    +           boolean doesProvideNewPage()
    +           {
    +                   return (pageId == null || failedToFindStoredPage) && 
pageClass != null;
    +           }
    +
    +           boolean didFailToFindStoredPage()
    +           {
    +                   return failedToFindStoredPage;
    +           }
    +
    +           Provision resolveTo(IRequestablePage page)
    +           {
    +                   this.page = page;
    +
    +                   return this;
    +           }
    +
    +           Provision resolve()
    +           {
    +
    +                   if (pageId != null)
    +                   {
    +                           IRequestablePage stored = 
getPageSource().getPageInstance(pageId);
    +                           if (stored != null && (pageClass == null || 
pageClass.equals(stored.getClass())))
    +                           {
    +
    +                                   page = stored;
    +
    +                                   if (renderCount != null && 
page.getRenderCount() != renderCount)
    +                                           throw new 
StalePageException(page);
    +                           }
    +
    +                           failedToFindStoredPage = page == null;
    +                   }
    +
    +                   return this;
    +           }
    +
    +           void detach()
    +           {
    +                   if (page != null)
    --- End diff --
    
    Well, if the old code detached it then let's keep it.
    There is an open ticket in JIRA that sometimes a Page is detached twice in 
the same request cycle, that's why I've asked.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to