Aksel Willgert
Aksel Willgert

Reputation: 11557

Primefaces components to update when commandButton is clicked

Lets say we have button

<h:form>
<p:commandButton id="refreshButton" value="refresh all depending components"/>
</h:form>

Along the way I will add components that should be updated when the button is clicked. So using the update="text1,text2" will not suffice, as text3 might be added later on and shouldn't require changes to the refresh button.

<h:outputText id="text1" value="{bean.someValue1}></h:outputText>
<h:outputText id="text2" value="{bean.someValue2}></h:outputText>

... and later ...

<h:outputText id="text3" value="{bean.someValue3}></h:outputText>

What I want to do is to bind the components to the button, rather than the button having dependencies to the components

Upvotes: 2

Views: 9556

Answers (2)

Aksel Willgert
Aksel Willgert

Reputation: 11557

I did a a temporary quickfix by using

<p:outputPanel autoUpdate="true">
    <h:outputText id="text3" ... />
<p:outputPanel />

Guess it performance wise is not perfect, as it will be updated on all ajax events and not just the ones I'm interested in. But luckily this component is interested in all of them any ways, so it is not a problem atm.

Upvotes: 1

BalusC
BalusC

Reputation: 1109695

What you're asking is not possible. As least, not using the standard ways in the view.

But what is possible is to reference a common parent instead.

<p:commandButton ... update="texts" />

...

<h:panelGroup id="texts">
    <h:outputText id="text1" ... />
    <h:outputText id="text2" ... />
    ...
    <h:outputText id="text3" ... />
</h:panelGroup>

Depending on the concrete functional requirement, which isn't clear from the question, there may be better solutions. But if it boils down to laziness and/or avoiding to "forget" to change the button, then I'm afraid that there's no magic fix.

Upvotes: 5

Related Questions