本文介绍了JSF 2/primefaces:p:panel无法用ajax渲染吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定此行为是否正常.
我希望仅在单击触发ajax请求的按钮后才会呈现我的panel.

Im not sure if this behaviour is normal or not.
Im hoping that my panel will be rendered only after clicking on a button that triggers an ajax request.

不使用Ajax可以正常工作:

Not using Ajax works fine :

  1. p:panel id="myPanel" rendered="#{myBean.flag}"
  2. p:commandButton ajax="false" action="#{myBean.setFlagToTrue}"
  3. 单击按钮之前,不会显示myPanel (flag = false)
  4. 单击按钮,将标志设置为true,并且myPanel呈现良好
  1. p:panel id="myPanel" rendered="#{myBean.flag}"
  2. p:commandButton ajax="false" action="#{myBean.setFlagToTrue}"
  3. before clicking the button, the myPanel is not displayed (flag = false)
  4. clicking the button, will set the flag to true, and myPanel is rendered fine

使用ajax失败:

  1. p:panel id="myPanel" rendered="#{myBean.flag}"
  2. p:commandButton ajax="true" action="#{myBean.setFlagToTrue}" update="myPanel"
  3. 单击按钮之前,不会显示myPanel (flag = false)
  4. 单击按钮,将标志设置为true(如我的日志文件所显示),并且myPanel 未呈现
  1. p:panel id="myPanel" rendered="#{myBean.flag}"
  2. p:commandButton ajax="true" action="#{myBean.setFlagToTrue}" update="myPanel"
  3. before clicking the button, the myPanel is not displayed (flag = false)
  4. clicking the button, will set the flag to true (as displayed by my log file), and myPanel is not rendered

我尝试省略了render属性,确实ajax可以正常工作.
我可以通过查看面板内部反映的变化来说明这一点.

I've tried omitting the rendered attribute, and indeed the ajax works fine.
I can tell that by looking at the changes reflected inside the panel.

推荐答案

将具有条件渲染的面板放到另一个面板中并进行更新.像这样:

put your panel with conditional rendering inside another and update it. Like this:

<p:outputPanel id="toUpdate">
  <p:panel id="myPanel" rendered="#{myBean.flag}">
  </p:panel>
<p:outputPanel>

<p:commandButton update="toUpdate"/>

这是一个已知问题.如果该元素在DOM中不存在,则无法更新.

This is a known issue. The element can't be updated if it doesn't exist in DOM.

这篇关于JSF 2/primefaces:p:panel无法用ajax渲染吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 15:18