【问题标题】:Toggle <p:panel visibility> on change of <p:selectOneRadio>在 <p:selectOneRadio> 更改时切换 <p:panel visibility>
【发布时间】:2016-06-22 09:53:13
【问题描述】:

我想在选择&lt;p:selectOneRadio&gt; 的项目时显示&lt;p:panel&gt;。第一次选择时它工作,但在ajax调用后它停止工作。

<p:selectOneRadio id="console" value="#{myBean.membre}">
    <f:selectItem itemLabel="a" itemValue="false" />
    <f:selectItem itemLabel="b" itemValue="true" />
    <p:ajax update="panel2,panel1" />
</p:selectOneRadio>
<p:panel id="panel1" visible="#{myBean.membre == false}"
    closable="true" toggleable="true">
    <ui:include src="a.xhtml" />
</p:panel>
<p:panel id="panel2" visible="#{myBean.membre == true}"
    closable="true" toggleable="true">
    <ui:include src="b.xhtml" />
</p:panel>

【问题讨论】:

  • 您是否在选择ab 单选按钮时检查了myBeanmembre 值是否从真变为假,反之亦然?
  • 它会改变,但在选择项目时它不会调用
  • 您使用的是什么版本的 PrimeFaces?

标签: jsf primefaces panel selectoneradio ajax-update


【解决方案1】:

在 PrimeFaces 4.0 上,我必须先从面板中删除可关闭的属性,然后才能切换可见性。我还添加了一个表单,在使用表单字段时总是需要它。

这是我的工作解决方案:

<h:form id="testForm">
  <p:selectOneRadio id="console" value="#{myBean.membre}">
    <f:selectItem itemLabel="a" itemValue="false" />
    <f:selectItem itemLabel="b" itemValue="true" />
    <p:ajax update="panel2,panel1" />
  </p:selectOneRadio>
  <p:panel id="panel1" visible="#{not myBean.membre}" toggleable="true">
       test 111
  </p:panel>
  <p:panel id="panel2" visible="#myBean.membre}" toggleable="true">
     test 222
  </p:panel>
</h:form>

为什么可关闭属性与可见属性冲突我不知道。这可能是一个错误或计划外的组合。

【讨论】:

  • 我已将代码放在其他页面中并且效果很好,但是当我在其他页面中使用 ui:include 调用它时,ajax 停止工作!有什么想法吗?
  • 没问题,问题解决了,我把我的bean改成@SessionScoped(它是@ViewScoped)
猜你喜欢
  • 1970-01-01
  • 2019-09-07
  • 1970-01-01
  • 1970-01-01
  • 2016-09-30
  • 2015-10-19
  • 2010-09-30
  • 2020-12-16
  • 2014-02-12
相关资源
最近更新 更多