tgallei
tgallei

Reputation: 859

Primefaces autoUpdate only works once

I have a page with different calculations, which are done by ajax.
At the end of the page there should be a hint text, which is updated after each calculation.

For this I use the autoUpdate feature of Primefaces.

When I load the page initially the text is displayed correctly. Also after the first calculation the text is refreshed correctly. But if I do further calculations, the text will not be changed anymore, no matter which value balanceController.getBalance() returns.
When I debug my code I see that balanceController.getDetails() runs correctly and also returns the desired text. Only the content on my page is not refreshed. When I manually reload the page (with the browser) the correct text appears.

What could be the cause that <p:autoUpdate/> is only executed during the first calculation and updates the tab content?

balancePage.xhtml

<p:tab title="Further details" rendered="#{balanceController.showDetails()}">
    <p:autoUpdate/>

    <h:outputText value="#{balanceController.details}"/>
</p:tab>

BalanceController.java

public String getDetails() {
    if ( getBalance() >= 0 ) {
        return "Your current balance is: " + Double.toString(getBalance());
    } else {
        return "Your credit has been used up!";
    }
}

Upvotes: 0

Views: 1157

Answers (1)

tandraschko
tandraschko

Reputation: 2346

In general a p:tab is not updateable, as the one who renders the p:tab is the parent component. Probably a p:accordionPanel or p:tabView.

So you can either move the p:autoUpdate to the parent component or move it inside the h:outputText.

NOTE: you probably need to add a id to the h:outputText as only components with rendered id are updatetable and h:outputText skips rendering the id when no id attribute is explicitly set.

Its also possible to solve it by wrapping it a p:outputPanel:

<p:tab title="Further details" rendered="#{balanceController.showDetails()}">
    <p:outputPanel>
       <p:autoUpdate/>
       #{balanceController.details}
    </p:outputPanel>
</p:tab>

I removed the h:outputText by performance reasons. IMO one should not use h:outputText for simple text (escape is not set to false) as this creates a UICompoment on the server side, which is not required.

Upvotes: 6

Related Questions