【问题标题】:Render p:outputPanel after every AJAX Call每次 AJAX 调用后渲染 p:outputPanel
【发布时间】:2013-01-27 03:08:18
【问题描述】:

我有一个 p:outputPanel,如果我有一个带有数据的 Java 对象,我想渲染它。如果对象为 null,我不想渲染面板。

<h:form id="treeform">
    <p:outputPanel id="outputComponent" rendered="#{TreeViewController.compProfile}">
        <div>
            .........
        </div>
    </p:outputPanel>
</h:form>

public boolean getCompProfile()
{

    if (cd == null)
    {
        return false;
    }
    else
    {
        return true;
    }
}

我注意到代码运行正常。如果对象为 null,则布尔值为 false,并且不显示面板。但是我发现的问题是,当我再次进行 AJAX 调用时,无论 Java 对象是否为空,布尔值始终为 false。我可以在 AJAX 调用后以某种方式配置 p:outputPanel 以检查 #{TreeViewController.compProfile} 属性是否呈现面板。

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    改变

    <p:outputPanel id="outputComponent" rendered="#{TreeViewController.compProfile}">
    

    进入

    <p:outputPanel autoUpdate="true">
        <p:outputPanel  id="outputComponent" rendered="#{TreeViewController.compProfile}">
    </p:outputPanel>
    

    或者不添加包装器并将treeform id 添加到您的ajax 的update 属性(p:ajax 或p:commandButton)

    点赞update="treeform"

    【讨论】:

    • 如果组件没有首先呈现,那么它就不能自动更新。另外,对于autoUpdate="true",无需在update 中指定其客户端ID。
    • 这样更好。我只是想知道哪些绵羊之前两次投了错误的答案。
    猜你喜欢
    • 2020-11-22
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多