我有两个具有 rendered
属性的 p:ouputPanels
。当底层 getter/setter 的值发生变化时,应该渲染它们。但是,基础值会按正确的顺序发生变化。第一个面板消失,但第二个面板不显示。即使不在 HTML 代码中!
我的两个面板:
<p:outputPanel id="PanelParent">
<h:form>
<p:outputPanel id="PanelForm" rendered="#{PageService.isVisibilityForm()}">
<h:commandButton value="Button"
action="#{PageService.persist}"
styleClass="btn btn-primary opal_btn submit_form_new" />
</h:form>
</p:outputPanel>
<p:outputPanel id="PanelMessage" rendered="#{PageService.isVisibilityMessage()}">
//Message
</p:outputPanel>
</p:outputPanel>
非常感谢您的回答!!!
-更新-
在代码中,我引用了 persist 方法,并在该方法中更改了每个部分的可见性的 getter 和 setter。
-更新1-
好吧,这实际上是我的代码:
<p:outputPanel id="parentPanel">
<p:outputPanel id="PanelForm"
rendered="#{PageService.isVisibilityForm()}">
<div>
<div>
<h:form class="homepage_invitee_form" action="" method="POST">
<p:messages id="messages" showDetail="false" autoUpdate="true"
closable="true" />
<h:inputText required="true"
value="#{PageService.instance.name}"
name="name" placeholder="Last Name"
styleClass="lastname_new" id="lastname_new"
type="text placeholder" />
<h:commandButton value="Press"
action="#{PageService.persist()}"/>
<f:ajax render="" />
</h:commandButton>
</h:form>
</div>
</div>
</p:outputPanel>
<p:outputPanel id="PanelThank"
rendered="#{PageService.isVisibilityThank()}">
<div>
Message
</div>
</p:outputPanel>
</p:outputPanel>
我真的没看出哪里失败了? ;(
最佳答案
就像 Xtreme Biker 所说的 <f:ajax>
render
属性将渲染 DOM 中已经存在的元素。在你的情况下,<p:outputPanel id="PanelThank">
render
属性评估结果为 false
所以它不在 DOM 中。因此,<f:ajax>
无法渲染它。您需要指向始终可见的东西。改变
<f:ajax render="" />
到
<f:ajax render=":PanelThank" />
但更重要的是改变
<p:outputPanel id="PanelThank" rendered="#{PageService.isVisibilityThank()}">
<div>
Message
</div>
</p:outputPanel>
至
<p:outputPanel id="PanelThank">
<p:outputPanel rendered="#{PageService.isVisibilityThank()}">
<div>
Message
</div>
</p:outputPanel>
</p:outputPanel>
也请考虑重构您的代码。例如,action
和method
在<h:form>
不需要。
关于jsf - p :outputPanel does not render page sections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17744658/