Primefaces单击commandButton时要更新的组件

Aks*_*ert 2 ajax primefaces jsf-2

让我们说我们有按钮

<h:form>
<p:commandButton id="refreshButton" value="refresh all depending components"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)

在此过程中,我将添加在单击按钮时应更新的组件.所以使用update ="text1,text2"是不够的,因为text3可能会在以后添加,并且不需要更改刷新按钮.

<h:outputText id="text1" value="{bean.someValue1}></h:outputText>
<h:outputText id="text2" value="{bean.someValue2}></h:outputText>
Run Code Online (Sandbox Code Playgroud)

... 然后 ...

<h:outputText id="text3" value="{bean.someValue3}></h:outputText>
Run Code Online (Sandbox Code Playgroud)

我想要做的是将组件绑定到按钮,而不是依赖于组件的按钮

Bal*_*usC 5

你问的是不可能的.至少,不要在视图中使用标准方式.

但可能的是引用一个共同的父母.

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

...

<h:panelGroup id="texts">
    <h:outputText id="text1" ... />
    <h:outputText id="text2" ... />
    ...
    <h:outputText id="text3" ... />
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)

根据具体的功能要求,从问题中不清楚,可能有更好的解决方案.但如果它归结为懒惰和/或避免"忘记"改变按钮,那么我担心没有神奇的修复.