You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by vp143 <vi...@cipriati.co.uk> on 2014/02/03 10:33:28 UTC
Re: AjaxLazyLoadPanel loading asynchronously
Martin Grigorov-4 wrote
> Hi,
>
> Create a panel that has a child an image (the busy indicator).
> Add a timer behavior to this panel and check whether the slow operation is
> done and replace the image with another component that renders the new
> data:
>
> public void onTimer(AjaxRequestTarget target) {
> Data newData = getNewData();
> if (newData != null)
> {
> NewComponent c = new Component(image.getId(), newData);
> image.replaceWith(c);
> target.add(c);
> }
> else {
> // target.appendJavaScript("still waiting ...");
> }
>
> }
>
> Martin Grigorov
> Wicket Training and Consulting
Thanks Martin!
This pattern seems very similar to
https://gist.github.com/jonnywray/594468 and
https://gist.github.com/jonnywray/636875
which I have seen referenced in some posts here.
While trying these, I am finding in FutureUpdateBehavior, onTimer(), the
line if(future.isDone()) is null most times (not all).
I am not quite sure why this would be.
When it is null, the constructor value passed through is not null, but is
null within onTimer.
Any ideas on this?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLazyLoadPanel-loading-asynchronously-tp4664035p4664140.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AjaxLazyLoadPanel loading asynchronously
Posted by vp143 <vi...@cipriati.co.uk>.
I found that I was received the NPE with the transient variable when
executing the same class twice concurrently, which makes sense now.
I went with the following (stripped back show only necessary code):
@SpringBean
private SupplierConnector supplierPrices;
private class GetPrices extends AjaxLazyLoadPanel {
public GetPrices(String id, final PageParameters changeDatesParam) {
super(id);
}
public Component getLoadingComponent(String markupId) {
return new Label(markupId, "");
}
@Override
public Component getLazyLoadComponent(String markupId) {
Wholesaler1 wholesaler1 = new Wholesaler1();
Wholesaler2 wholesaler2 = new Wholesaler2();
Future<List<Result>> wholesaler1List =
supplierPrices.getWholesaler1Prices(wholesaler1, searchFields);
Future<List<Result>> wholesaler2List =
supplierPrices.getWholesaler2Prices(wholesaler2, searchFields);
while(!(wholesaler1List.isDone() && wholesaler2List.isDone())) {
try {
Thread.sleep(100); //pause between each check
}
catch(Exception e) {
log.error("Thread sleep exception");
}
}
try {
SearchResults.this.results.addAll(wholesaler1.get());
SearchResults.this.results.addAll(wholesaler2.get());
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AjaxRequestTarget resultsTarget =
resultsContainer.getRequestCycle().find(AjaxRequestTarget.class);
resultsTarget.add(resultsContainer);
AjaxRequestTarget progressTarget =
progressBar.getRequestCycle().find(AjaxRequestTarget.class);
progressTarget.add(progressBar);
return new Label(markupId, "");
}
}
In the SupplierConnector class
@Async
public Future<List<HotelRoomResult>> getWholesaler1Prices(Wholesaler
wholesaler, SearchFields searchFields) {
//Do time consuming operation
return new AsyncResult<List<Result>>(results);
}
I am using a progress bar instead of an ajax indicator and the
resultsContainer contains the display showing the results obtained.
I hope it helps others
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLazyLoadPanel-loading-asynchronously-tp4664035p4665188.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AjaxLazyLoadPanel loading asynchronously
Posted by Bas Gooren <ba...@iswd.nl>.
Hi,
When your page gets serialized (which can happen between requests),
transient fields (like the "future" field) are set to null.
When your behavior is triggered and the page is deserialized, the field
is null.
Met vriendelijke groet,
Kind regards,
Bas Gooren
schreef vp143 op 3-2-2014 15:16:
> I cannot get future here
> (https://gist.github.com/jonnywray/636875#file-futureupdatebehavior-java-L31)
> to have a value.
> I do not understand when/how it gets deserialized?
>
>
> Martin Grigorov-4 wrote
>> Because it is transient:
>> https://gist.github.com/jonnywray/636875#file-futureupdatebehavior-java-L19
>> After deserialization it will be null.
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLazyLoadPanel-loading-asynchronously-tp4664035p4664151.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: AjaxLazyLoadPanel loading asynchronously
Posted by vp143 <vi...@cipriati.co.uk>.
I cannot get future here
(https://gist.github.com/jonnywray/636875#file-futureupdatebehavior-java-L31)
to have a value.
I do not understand when/how it gets deserialized?
Martin Grigorov-4 wrote
> Because it is transient:
> https://gist.github.com/jonnywray/636875#file-futureupdatebehavior-java-L19
> After deserialization it will be null.
>
> Martin Grigorov
> Wicket Training and Consulting
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLazyLoadPanel-loading-asynchronously-tp4664035p4664151.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: AjaxLazyLoadPanel loading asynchronously
Posted by Martin Grigorov <mg...@apache.org>.
Because it is transient:
https://gist.github.com/jonnywray/636875#file-futureupdatebehavior-java-L19
After deserialization it will be null.
Martin Grigorov
Wicket Training and Consulting
On Mon, Feb 3, 2014 at 10:33 AM, vp143 <vi...@cipriati.co.uk> wrote:
> Martin Grigorov-4 wrote
> > Hi,
> >
> > Create a panel that has a child an image (the busy indicator).
> > Add a timer behavior to this panel and check whether the slow operation
> is
> > done and replace the image with another component that renders the new
> > data:
> >
> > public void onTimer(AjaxRequestTarget target) {
> > Data newData = getNewData();
> > if (newData != null)
> > {
> > NewComponent c = new Component(image.getId(), newData);
> > image.replaceWith(c);
> > target.add(c);
> > }
> > else {
> > // target.appendJavaScript("still waiting ...");
> > }
> >
> > }
> >
> > Martin Grigorov
> > Wicket Training and Consulting
>
> Thanks Martin!
> This pattern seems very similar to
> https://gist.github.com/jonnywray/594468 and
> https://gist.github.com/jonnywray/636875
> which I have seen referenced in some posts here.
>
> While trying these, I am finding in FutureUpdateBehavior, onTimer(), the
> line if(future.isDone()) is null most times (not all).
>
> I am not quite sure why this would be.
> When it is null, the constructor value passed through is not null, but is
> null within onTimer.
>
> Any ideas on this?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/AjaxLazyLoadPanel-loading-asynchronously-tp4664035p4664140.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>