[
https://issues.apache.org/jira/browse/WICKET-6055?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15071007#comment-15071007
]
ASF GitHub Bot commented on WICKET-6055:
----------------------------------------
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.
> AjaxLazyLoadPanel should provide non-blocking lazy load
> -------------------------------------------------------
>
> Key: WICKET-6055
> URL: https://issues.apache.org/jira/browse/WICKET-6055
> Project: Wicket
> Issue Type: Improvement
> Components: wicket-extensions
> Affects Versions: 7.1.0
> Reporter: Martijn Dashorst
> Assignee: Martijn Dashorst
>
> When having multiple AjaxLazyLoadPanels on your page, they all block their
> Wicket request thread until the content is ready to load. This can be
> problematic when you try to wait for some background job to finish and want
> to poll for that job to be ready, and only then update the contents.
> The improvement would be to add a method that gives the developer the option
> to not update just yet (isReadyForReplacement) and when it returns true,
> start the replacement. By default this would return true, implementing the
> current behavior of the AjaxLazyLoadPanel.
> Furthermore to improve the responsiveness of the ALLP it should add a single
> timer to the page that can be used by multiple ALLPs to update themselves.
> The timer would poll each second and the ALLPs would use Wicket's event bus
> to update themselves. With some reference counting, the timer can remove
> itself from the page when all ALLPs have updated themselves.
> This enables refreshing the page as well when outside an AJAX context, or
> having a user be impatient and pressing F5.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)