jsf - p :outputPanel does not render page sections

标签 jsf jsf-2 primefaces

我有两个具有 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>

也请考虑重构您的代码。例如,actionmethod<h:form>不需要。

关于jsf - p :outputPanel does not render page sections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17744658/

相关文章:

jsf - 如何在 JSF 中设置 dataTable 渲染列的宽度?

jsf - 防止双重提交的纯 Java/JSF 实现

java - primefaces:确认对话框按钮不调用托管bean方法

jsf - 在 <h :inputText> to cover all changes 上使用哪个事件

javascript - 检查f :items value based on p:selectManyCheckbox using javascript

jsf - p:dataTable initial SortBy with dynamic columns

java - JSF默认tomcat错误页面

java - 使用 Java 泛型为实体实现转换器

Tomcat 8 找不到 com.sun.faces.config.ConfigureListener 类

javascript - 如何覆盖 Primefaces 中的 ContentFlow 配置