Primefaces单击commandButton时要更新的组件

时间:2012-09-08 14:10:15

标签: ajax jsf-2 primefaces

让我们说我们有按钮

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

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

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

......以后......

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

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

2 个答案:

答案 0 :(得分:5)

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

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

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

...

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

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

答案 1 :(得分:1)

我使用

做了一个临时的quickfix
<p:outputPanel autoUpdate="true">
    <h:outputText id="text3" ... />
<p:outputPanel />

猜测性能明智并不完美,因为它会更新所有ajax事件而不仅仅是我感兴趣的事件。但幸运的是这个组件对所有这些都感兴趣,所以这不是问题大气压。