Github user martin-g commented on a diff in the pull request:
https://github.com/apache/wicket/pull/151#discussion_r48414551
--- Diff:
wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/LazyLoadingPage.java
---
@@ -16,38 +16,100 @@
*/
package org.apache.wicket.examples.ajax.builtin;
+import java.util.Random;
+
import org.apache.wicket.Component;
import org.apache.wicket.extensions.ajax.markup.html.AjaxLazyLoadPanel;
import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.panel.EmptyPanel;
+import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.util.time.Duration;
-/**
- * @author jcompagner
- */
+@SuppressWarnings({ "javadoc", "serial" })
public class LazyLoadingPage extends BasePage
{
- /**
- * Construct.
- */
+ private Random r = new Random();
+
public LazyLoadingPage()
{
- add(new AjaxLazyLoadPanel("lazy")
+ add(new Link<Void>("startNonblocking")
+ {
+ @Override
+ public void onClick()
+ {
+ addNonBlockingPanels();
+ }
+ });
+ add(new Link<Void>("startBlocking")
{
-
@Override
- public Component getLazyLoadComponent(String id)
+ public void onClick()
{
- // sleep for 5 seconds to show the behavior
- try
+ addBlockingPanels();
+ }
+ });
+
+ add(new EmptyPanel("lazy"));
+ add(new EmptyPanel("lazy2"));
+ }
+
+ private void addNonBlockingPanels()
+ {
+ RepeatingView rv;
+ addOrReplace(rv = new RepeatingView("lazy"));
+
+ for (int i = 0; i < 10; i++)
+ rv.add(new AjaxLazyLoadPanel(rv.newChildId())
+ {
+ private static final long serialVersionUID = 1L;
+
+ private long startTime =
System.currentTimeMillis();
+
+ private int seconds = r.nextInt(10);
+
+ @Override
+ protected boolean isReadyForReplacement()
{
- Thread.sleep(5000);
+ return
Duration.milliseconds(System.currentTimeMillis() - startTime)
+ .seconds() > seconds;
}
- catch (InterruptedException e)
+
+ @Override
+ public Component getLazyLoadComponent(String id)
{
- throw new RuntimeException(e);
+ return new Label(id, "Lazy Loaded after
" + seconds + " seconds");
}
- return new Label(id, "Lazy Loaded after 5
seconds");
- }
+ });
+ }
- });
+ private void addBlockingPanels()
+ {
+ RepeatingView rv;
+ addOrReplace(rv = new RepeatingView("lazy2"));
+
+ for (int i = 0; i < 5; i++)
+ rv.add(new AjaxLazyLoadPanel(rv.newChildId())
+ {
+ private static final long serialVersionUID = 1L;
+
+ private int seconds = r.nextInt(5);
+
+ @Override
+ public Component getLazyLoadComponent(String
markupId)
+ {
+ try
+ {
+ System.out.println("Starting
sleep");
--- End diff --
Use Logger instead.
---
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.
---