I'm using JSF 2.2, PrimeFaces 6 and Spring Framework 4.3 in my web application.
Users are redirected to the homepage after they logged in. In the homepage there are some charts, tables etc. are loaded. They show some real-time information and it takes some time to load the homepage. I don't want the user wait in login page too long. So I used the following code to load charts after page load as stated in here:
<h:form id="hiddenForm" style="display: none;">
<p:remoteCommand name="onload" actionListener="#{homeMB.onload}"
update=":firstChartForm :secondChartForm :thirdChartForm" global="false"/>
</h:form>
And this is the onload method of backing bean:
public void onload() {
fillFirstChart(); //Takes 5 seconds
fillSecondChart(); //Takes 1 second
fillThirdChart(); // Takes 3 seconds.
}
Charts are filled by those methods and updated with the help of update
parameter of p:remoteCommand
, but it takes 9 seconds. I want to run those methods concurrently and update each of those charts with the datas provided by corresponding methods as soon as the datas are loaded.
I mean, users should be redirected to the homepage as soon as they clicked on login button, and in the homepage firstly SecondChart should be filled/updated in 1 second, and 2 seconds later ThirdChart filled/updated, and finally 2 seconds later FirstChart should be filled/updated. So it should take ~5 seconds in total.
EDIT: This answer does not work for me because when I load the charts asynchronously, JSF waits for the slowest one to update them all. Ok, it takes 5 seconds instead of 9 seconds in total but as I stated "in the homepage firstly SecondChart should be filled/updated in 1 second, and 2 seconds later ThirdChart filled/updated, and finally 2 seconds later FirstChart should be filled/updated". But if I apply the way described in the first answer, they are all updated in 5 seconds
This answer may be applied. I mean, as soon as the user clicks to login button, the server can gather and push the datas to the charts and they can be updated from backing bean by RequestContext.getCurrentInstance().update("foo:bar");
as showed here. But I thought there could be some easier way for this because I think many people may have faced a similar problem before.
Thanks.