0

I have a simple table [form:tabView:remTNtableID], with a list of strings CFSnumbers, and when I click a button I call getTelephoneNumbers() to fill it, which takes a while.

I'd like to have the table show "Loading.." while waiting, and for that purpose I cleared the list, added "Loading.." to the list, and called RequestContext.getCurrentInstance().update("form:tabView:remTNtableID").

But the table is not updated immediately, "Loading.." is not seen, and only when the getTelephoneNumbers() call ends is the table updated.

What's up? How can I force the table to be re-rendered immediately?

private List<String> CFSnumbers;

@PostConstruct
public void init() throws GuiException {
    CFSnumbers = new ArrayList<String>();
}

public void getTelephoneNumbers() throws GuiException {
    CFSnumbers.clear();
    CFSnumbers.add("Loading..");
    RequestContext.getCurrentInstance().update("form:tabView:remTNtableID");
    try {
        ...
        CFSnumbers = ...
        RequestContext.getCurrentInstance().update("form:tabView:remTNtableID");
    } catch (Exception e) {
        CFSnumbers.clear();
        RequestContext.getCurrentInstance().update("form:tabView:remTNtableID");
    }
WurmD
  • 1,231
  • 5
  • 21
  • 42
  • are you interested to make a different solution for your `Loading` ?!? – Yagami Light Oct 06 '16 at 14:23
  • @YagamiLight uuh, what? At the moment my table when empty shows "No records." I'd like when I click the button for it to show "Loading..", and then after the seconds when my call to retrieve the numbers that will fill the table returns, for it to show the list of numbers. Atm it just starts at "No records.", stays at "No records." for the many seconds, and then, when the call ends, shows the list of numbers. – WurmD Oct 06 '16 at 14:51
  • please see this post about AjaxStatus http://stackoverflow.com/questions/39897415/can-use-ajaxstatus-while-the-next-page-is-loading/39897555#39897555 – Yagami Light Oct 06 '16 at 14:54
  • @YagamiLight Hmm, if I got that right, that question/answer is to show and overlaid "LOADING" image that prevents the user from interacting with the page. Thank you for that suggestion, but that is not my question nor request. Do you know if it is possible for in the middle of a Bean function to re-render the page? (atm it seems only in between bean calls is the page rendered) – WurmD Oct 06 '16 at 14:59

1 Answers1

0

The action getTelephoneNumbers() is a single request. All updates are executed (send in the response) when your method has been fully executed.

What you could do is split your action into a reset part and a heavy loading part. When you click the button, call reset which resets and updates your table saying "Loading...". When the reset is completed, use a remoteCommand to start the actual heavy loading, and update the table when it completes.

So, in your XHTML:

<p:remoteCommand name="getTelephoneNumbersRemoteCommand"
                 action="#{yourBean.getTelephoneNumbers}"
                 update="remTNtableID"/>
<p:commandButton ...
                 action="#{yourBean.preGetTelephoneNumbers}"
                 update="remTNtableID"
                 oncomplete="getTelephoneNumbersRemoteCommand()"/>

And in your bean:

public void preGetTelephoneNumbers() {
    CFSnumbers.clear();
    CFSnumbers.add("Loading..");
}

public void getTelephoneNumbers() {
    try {
        ...
        CFSnumbers = ...
    } catch (Exception e) {
        CFSnumbers.clear();
    }
}

Updating from your bean is no longer necessary, as it is done in the XHTML.

Related:

Community
  • 1
  • 1
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102