Repository: wicket
Updated Branches:
  refs/heads/master 426de3276 -> 147f6d33f


WICKET-6608 Stateless page, mix of queue and add can cause unforseen
consequences

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/147f6d33
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/147f6d33
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/147f6d33

Branch: refs/heads/master
Commit: 147f6d33f839edd9a6eb53ce9c20b4cde07fc938
Parents: 426de32
Author: Andrea Del Bene <[email protected]>
Authored: Tue Nov 6 15:29:03 2018 +0100
Committer: Andrea Del Bene <[email protected]>
Committed: Tue Nov 6 15:31:05 2018 +0100

----------------------------------------------------------------------
 .../handler/PageAndComponentProvider.java       | 50 +++++++++++++-------
 1 file changed, 32 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/147f6d33/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageAndComponentProvider.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageAndComponentProvider.java
 
b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageAndComponentProvider.java
index 0638c9b..785c4a7 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageAndComponentProvider.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/PageAndComponentProvider.java
@@ -158,27 +158,10 @@ public class PageAndComponentProvider extends 
PageProvider implements IPageAndCo
                        component = page != null ? page.get(componentPath) : 
null;
                        if (component == null)
                        {
-
-                               /*
-                                * on stateless pages it is possible that the 
component may not yet exist because it
-                                * couldve been created in one of the lifecycle 
callbacks of this page. Lets invoke
-                                * the callbacks to give the page a chance to 
create the missing component.
-                                */
-
                                // make sure this page instance was just 
created so the page can be stateless
                                if (page.isPageStateless())
                                {
-                                       Page p = (Page)page;
-                                       p.internalInitialize();
-                                       
-                                       // preparation of feedbacks is delayed 
into the render phase
-                                       try (FeedbackDelay delay = new 
FeedbackDelay(p.getRequestCycle())) {
-                                               p.beforeRender();
-                                               p.markRendering(false);
-                                               
-                                               // note: no invocation of 
delay.onBeforeRender() 
-                                       }
-                                       component = page.get(componentPath);
+                                       component = 
resolveStatelessPageComponent((Page)page);
                                }
                        }
                }
@@ -191,6 +174,37 @@ public class PageAndComponentProvider extends PageProvider 
implements IPageAndCo
        }
 
        /**
+        * On stateless pages it is possible that the component may not yet 
exist because it
+        * could have been created in one of the lifecycle callbacks of this 
page. Lets invoke
+        * the callbacks to give the page a chance to create the missing 
component.
+        **/
+       private IRequestableComponent resolveStatelessPageComponent(Page page)
+       {
+               //1-first let's try initializing the page
+               page.internalInitialize();
+               
+               IRequestableComponent component = page.get(componentPath);
+
+               if (component != null)
+               {
+                       return component;
+               }
+               
+               //2-if component has not been found let's try rendering the page
+               
+               // preparation of feedbacks is delayed into the render phase
+               try (FeedbackDelay delay = new 
FeedbackDelay(page.getRequestCycle())) 
+               {
+                       page.beforeRender();
+                       page.markRendering(false);
+                       
+                       // note: no invocation of delay.onBeforeRender() 
+               }
+               
+               return page.get(componentPath);
+       }
+
+       /**
         * @see 
org.apache.wicket.core.request.handler.IPageAndComponentProvider#getComponentPath()
         */
        @Override

Reply via email to