Repository: wicket
Updated Branches:
  refs/heads/master 400b003e9 -> 5fda8cee2


WICKET-6055 may be invisible

- so don't call isLoaded on each render
- install behavior on each render, in case the panel comes visible later
- don't trigger for non-visible panels
- added tests


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

Branch: refs/heads/master
Commit: 5fda8cee2c15d9526dc5a86e565cb01efe631311
Parents: 400b003
Author: Sven Meier <svenme...@apache.org>
Authored: Mon Feb 19 15:44:38 2018 +0100
Committer: Sven Meier <svenme...@apache.org>
Committed: Mon Feb 19 15:51:20 2018 +0100

----------------------------------------------------------------------
 .../ajax/markup/html/AjaxLazyLoadPanel.java     | 16 ++--
 .../markup/html/AjaxLazyLoadPanelTester.java    |  1 +
 .../ajax/markup/html/AjaxLazyLoadPanelPage.html | 24 ++++++
 .../ajax/markup/html/AjaxLazyLoadPanelPage.java | 72 ++++++++++++++++
 .../ajax/markup/html/AjaxLazyLoadPanelTest.java | 91 ++++++++++++++++++++
 5 files changed, 195 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/5fda8cee/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
----------------------------------------------------------------------
diff --git 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
index 783b64d..60e368e 100644
--- 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
+++ 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.java
@@ -173,11 +173,13 @@ public abstract class AjaxLazyLoadPanel<T extends 
Component> extends Panel
         * Installs a page-global timer if not already present.
         */
        @Override
-       protected void onInitialize()
+       protected void onBeforeRender()
        {
-               super.onInitialize();
+               super.onBeforeRender();
 
-               initTimer();
+               if (isVisibleInHierarchy() && loaded == false) {
+                       initTimer();
+               }
        }
 
        /**
@@ -193,9 +195,7 @@ public abstract class AjaxLazyLoadPanel<T extends 
Component> extends Panel
                        getPage().add(timer);
                        
                        
getRequestCycle().find(AjaxRequestTarget.class).ifPresent(target -> {
-                               // the timer will not be rendered, so stop it 
first
-                               // and restart it immediately on the Ajax 
request
-                               timer.stop(null);
+                               // the timer will not be rendered, so restart 
it immediately on the Ajax target
                                timer.restart(target);
                        });
                }
@@ -208,8 +208,6 @@ public abstract class AjaxLazyLoadPanel<T extends 
Component> extends Panel
 
                if (get(CONTENT_ID) == null) {
                        add(getLoadingComponent(CONTENT_ID));
-               } else {
-                       isLoaded();
                }
        }
 
@@ -292,7 +290,7 @@ public abstract class AjaxLazyLoadPanel<T extends 
Component> extends Panel
                                @Override
                                public void component(AjaxLazyLoadPanel<?> 
panel, IVisit<Void> visit)
                                {
-                                       if (panel.isLoaded() == false) {
+                                       if (panel.isVisibleInHierarchy() && 
panel.isLoaded() == false) {
                                                Duration updateInterval = 
panel.getUpdateInterval();
                                                if (getUpdateInterval() == 
null) {
                                                        throw new 
IllegalArgumentException("update interval must not ben null");

http://git-wip-us.apache.org/repos/asf/wicket/blob/5fda8cee/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
----------------------------------------------------------------------
diff --git 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
index 13a65b9..b136707 100644
--- 
a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
+++ 
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTester.java
@@ -61,6 +61,7 @@ public class AjaxLazyLoadPanelTester
                if (behaviors.size() == 0)
                {
                        logger.warn("No timer behavior for AjaxLazyLoadPanel 
found. A curious situation...");
+                       return;
                }
                else if (behaviors.size() > 1)
                {

http://git-wip-us.apache.org/repos/asf/wicket/blob/5fda8cee/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.html
----------------------------------------------------------------------
diff --git 
a/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.html
 
b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.html
new file mode 100644
index 0000000..b0cdd26
--- /dev/null
+++ 
b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.html
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<html>
+<body>
+       <div wicket:id="panel"></div>
+       
+       <a wicket:id="link"></a>
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/5fda8cee/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.java
----------------------------------------------------------------------
diff --git 
a/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.java
 
b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.java
new file mode 100644
index 0000000..856aa99
--- /dev/null
+++ 
b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelPage.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.extensions.ajax.markup.html;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+
+/**
+ */
+public class AjaxLazyLoadPanelPage extends WebPage
+{
+       private static final long serialVersionUID = 1L;
+       
+       public boolean contentReady = false;
+       
+       public final AjaxLazyLoadPanel<Component> panel;
+
+       public final AjaxLink<Void> link;
+
+       /**
+        * Construct.
+        */
+       public AjaxLazyLoadPanelPage()
+       {
+               panel = new AjaxLazyLoadPanel<Component>("panel")
+               {
+                       @Override
+                       protected boolean isContentReady()
+                       {
+                               return contentReady;
+                       }
+                       
+                       @Override
+                       public Component getLazyLoadComponent(String id)
+                       {
+                               return new Label(id, "LOADED");
+                       }
+               };
+               add(panel);
+               
+               link = new AjaxLink<Void>("link")
+               {
+                       @Override
+                       public void onClick(AjaxRequestTarget target)
+                       {
+                               if (panel.isVisible() == false) {
+                                       panel.setVisible(true);
+                               }
+                               
+                               target.add(panel);
+                       }
+               };
+               add(link);
+       }
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/5fda8cee/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTest.java
 
b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTest.java
new file mode 100644
index 0000000..35854cb
--- /dev/null
+++ 
b/wicket-extensions/src/test/java/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanelTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.extensions.ajax.markup.html;
+
+import org.apache.wicket.util.tester.WicketTestCase;
+import org.junit.Test;
+
+/**
+ * Test for {@link AjaxLazyLoadPanel}.
+ * 
+ * @author svenmeier
+ */
+public class AjaxLazyLoadPanelTest extends WicketTestCase
+{
+
+       @Test
+       public void immediatelyContentReady() {
+               
+               AjaxLazyLoadPanelPage page = new AjaxLazyLoadPanelPage();
+               page.contentReady = true;
+               
+               tester.startPage(page);
+               
+               // render the loading component at least once
+               tester.assertContainsNot("LOADED");
+
+               AjaxLazyLoadPanelTester.executeAjaxLazyLoadPanel(tester);
+               
+               tester.assertContains("LOADED");
+       }
+       
+       @Test
+       public void lateContentReady() {
+               
+               AjaxLazyLoadPanelPage page = new AjaxLazyLoadPanelPage();
+               page.contentReady = false;
+               
+               tester.startPage(page);
+               
+               tester.assertContainsNot("LOADED");
+               
+               AjaxLazyLoadPanelTester.executeAjaxLazyLoadPanel(tester);
+
+               tester.assertContainsNot("LOADED");
+
+               page.contentReady = true;
+               AjaxLazyLoadPanelTester.executeAjaxLazyLoadPanel(tester);
+               
+               tester.assertContains("LOADED");
+       }
+       
+       @Test
+       public void lateVisible() {
+               
+               AjaxLazyLoadPanelPage page = new AjaxLazyLoadPanelPage();
+               page.contentReady = true;
+               page.panel.setVisible(false);
+               
+               tester.startPage(page);
+               
+               // neither content nor timer since not visible 
+               tester.assertContainsNot("LOADED");
+               tester.assertContainsNot("Wicket.Timer.set\\(");
+
+               tester.clickLink(page.link);
+               
+               // no content yet, but timer  
+               tester.assertContainsNot("LOADED");
+               tester.assertContains("Wicket.Timer.set\\(");
+
+               AjaxLazyLoadPanelTester.executeAjaxLazyLoadPanel(tester);
+               
+               // content still, but no timer necessary anymore 
+               tester.assertContains("LOADED");
+               tester.assertContainsNot("Wicket.Timer.set\\(");
+       }
+}

Reply via email to