【问题标题】:show and hide primefaces tab via ajax depending on selectOneMenu's values - Hide a tab without update the tabview根据 selectOneMenu 的值通过 ajax 显示和隐藏 primefaces 选项卡 - 隐藏选项卡而不更新选项卡视图
【发布时间】:2017-10-09 10:33:37
【问题描述】:

p:tab 有问题。我用谷歌搜索了很多,但没有发现任何关于这个问题的信息。

我需要根据selectOneMenu 值的选择在tabView 中显示/隐藏tab。因此,我使用了 ajax,但问题是当我更改 selectOneMenu 的值时,所有表单输入都将被重置并且值会丢失。

<p:tab id="informationTab">     
  <h:outputLabel for="situationFamiliale" value="Situation  familiale: *" />
  <p:selectOneMenu id="situationFamiliale" value="#{bean.entity.attribut}" >
    <f:selectItem itemLabel="Celibataire" itemValue="Celibataire" />
    <f:selectItem itemLabel="Marie(e)" itemValue="Marie(e)" />
    <f:ajax event="change" render="@form" />
  </p:selectOneMenu>
</p:tab>

<p:tab id="id" rendered="#{bean.entity.attribut== 'Marie(e)'}" title="Information Menage">

</p:tab>    

【问题讨论】:

  • 尝试只更新选项卡 (update="id") 而不是重新呈现整个表单 (render="@form")。
  • 我已经尝试过这个解决方案,但是在这种情况下我的标签没有出现。

标签: ajax jsf jakarta-ee primefaces


【解决方案1】:

如果您使用&lt;f:ajax 而不使用execute=,则execute 的默认值为“@this”。因此,只有 SelectOneMenu 的值被发送到服务器。由于render="@form",整个表单将被重新渲染,所有其他更改都将丢失。

您应该使用f:ajax execute="@form" render="@form"...&gt;。问题是,如果你想出现/消失一个选项卡,你必须重新渲染整个选项卡视图。您不能使用已呈现的属性重新呈现单个选项卡。

【讨论】:

  • 这是我的问题,我确实想更新一个没有整个 tabView 的选项卡。它必须存在解决方案,不是吗?
  • 只有在选项卡可能保留在选项卡视图中但为空的情况下才有可能。 &lt;p:tab id="tabid"&gt;&lt;h:panelGroup rendered="#{myRenderingCondition}"&gt;。现在您可以使用&lt;f:ajax render="tabid"。如果您的 render= 位于不同的选项卡中,您可能必须使用 `render=":formid:tabid"。
猜你喜欢
  • 1970-01-01
  • 2013-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多