0

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!";
    }
}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
tgallei
  • 827
  • 3
  • 13
  • 22
  • is the `rendered` attribute `false` the second time? look at [this](https://stackoverflow.com/questions/14790014/ajax-update-render-does-not-work-on-a-component-which-has-rendered-attribute) – fuggerjaki61 Mar 10 '20 at 15:21
  • No, the rendered `attribute` is `true`, it's only a propertie which is loaded when the application starts. – tgallei Mar 10 '20 at 15:24
  • maybe try with updating via id. also check the browser's console (F12) – fuggerjaki61 Mar 10 '20 at 15:28
  • And always [mcve] and version info! – Kukeltje Mar 10 '20 at 15:46
  • 1
    And if you try this in a jsf/primeFaces panel instead of a tab, does it then also only works once? Hint: you cannot update individual tabs only the content of a tab or the whole tabview – Kukeltje Mar 10 '20 at 15:47

1 Answers1

6

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.

tandraschko
  • 2,291
  • 13
  • 13