p:commandButton呈现的属性在ajax更新后不起作用(Primefaces 3.5) [英] p:commandButton rendered property not working after ajax update (Primefaces 3.5)
问题描述
我检查了我的代码很多次,没有发现有关它的问题.
I reviewed my code lot of times and didnt find questions about it.
我对p:commandButton呈现的属性有疑问.即使getter方法返回false,也始终显示p:commandButton.发生在ajax更新之后.
I have a problem with p:commandButton rendered property. The p:commandButton is allways displayed even if the getter method returns false. That happens after an ajax update.
我有一个带有ap:ajax event ="change"的ap:selectOneMenu,用于设置MB并更新ap:commandButton(具有基于布尔型getter的呈现属性)和其他两个组件:第二个p:selectOneMenu和ap: outputLabel.
I have a p:selectOneMenu with a p:ajax event="change" that sets a MB and updates a p:commandButton (with a rendered property based on a boolean getter) and two other components: a second p:selectOneMenu and a p:outputLabel.
当我更改第一个p:selectOneMenu选择时,第二个p:selectOneMenu和p:outputLabel呈现没有问题,但是始终显示p:commandButton.呈现的属性不会更新.
The second p:selectOneMenu and the p:outputLabel are rendered without problems when I change the first p:selectOneMenu selection, but the p:commandButton is allways displayed. The rendered property is not updated.
如果刷新浏览器或设置了update ="@ form",则p:commandButton将正确显示/隐藏.但是请注意,所有组件都在同一个容器中.
If I refresh the browser or if I set the update="@form" the p:commandButton is displayed/hidden correctly. But note that all the components are in the same container.
我做错了什么?代码:
<p:selectOneMenu id="cmbPais" value="#{pessoaController.selected.endereco.pais}">
<f:selectItems value="#{paisController.itemsSelectOne}"/>
<p:ajax event="change" update="cmbEstado,btnBuscaPeloEndereco,test"/>
</p:selectOneMenu>
<p:outputLabel id="test" value="#{pessoaController.selected.endereco.ok}"/>
<p:commandButton id="btnBuscaPeloEndereco" icon="ui-icon-correios" type="button" onclick="dlgCEP.show();" rendered="#{pessoaController.selected.endereco.ok}"/>
<p:selectOneMenu id="cmbEstado" value="#{pessoaController.selected.endereco.estado}">
<f:selectItems value="#estadoController.getItemsSelectOne(pessoaController.selected.endereco.pais)}"/>
<f:ajax event="change" render="cmbCidade" />
</p:selectOneMenu>
推荐答案
您只能ajax更新始终呈现的组件(即,当它没有rendered
属性时). JSF ajax引擎不支持添加/删除HTML元素.它仅支持更改HTML元素.
You can only ajax-update a component which is always rendered (i.e. when it does not have a rendered
attribute). JSF ajax engine does not support addition/removal of a HTML element. It only supports the change of a HTML element.
因此,将其包装在始终呈现的组件中,然后对其进行ajax更新.
So, wrap it in a component which is always rendered and ajax-update it instead.
<p:selectOneMenu id="cmbPais" value="#{pessoaController.selected.endereco.pais}">
<f:selectItems value="#{paisController.itemsSelectOne}"/>
<p:ajax event="change" update="cmbEstado,btnBuscaPeloEndereco,test"/>
</p:selectOneMenu>
<h:panelGroup id="btnBuscaPeloEndereco">
<p:commandButton icon="ui-icon-correios" type="button" onclick="dlgCEP.show();" rendered="#{pessoaController.selected.endereco.ok}"/>
</h:panelGroup>