【问题标题】:Hide and show dataTable column with a button in Primefaces在 Primefaces 中使用按钮隐藏和显示 dataTable 列
【发布时间】:2013-03-11 10:41:37
【问题描述】:

我得到一个包含很多内容的数据表。对于每一行,我在最后一列得到一个 iFrame-Link。基于这些链接,页面需要很长时间才能加载。
现在我想隐藏此列以获得更快的加载。用户应该能够显示带有按钮的列。但我怎么能意识到这一点?以下是专栏内容:

<p:commandButton value="Show book">
  <f:setPropertyActionListener value="true" target="#{rollCommunityBean.renderPhoneColumn}" />
</p:commandButton>

<p:column exportable="false" rendered="#{rollCommunityBean.renderPhoneColumn}">
  <f:facet name="header">
    <h:outputText value="Link" />
  </f:facet>

  <p:lightBox iframe="true" width="750pt" height="650pt">
    <h:outputLink rendered="#{member.username.length() > 0}" value="url" title="#{member.username} - #{member.name} #{member.vorname}">
      <h:outputText icon="ui-icon-person" value="Telefonbuch" />
    </h:outputLink>
  </p:lightBox>
</p:column>

RollCommunityBean

public class RollCommunityBean {
    /*
     * All rendering Booleans
     */

    // For the Phonebook iFrame Column
    private boolean renderPhoneColumn;

    /*
     * All Getter and Setter for the rendering Booleans
     */
    public boolean getRenderPhoneColumn() {
        return renderPhoneColumn;
    }

    public void setRenderPhoneColumn(boolean renderPhoneColumn) {
        this.renderPhoneColumn = renderPhoneColumn;
    }
}

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    p:column 具有rendered 属性,因此您可以控制其渲染。你应该添加这个属性:

    <p:column exportable="false" rendered="#{myBean.renderIframeColumn}">
    

    并添加将您的属性设置为 true 的按钮:

    <p:commandButton value="Show column" update="table1">
      <f:setPropertyActionListener value="true" target="#{myBean.renderIframeColumn}"/>
    </p:commandButton>
    

    在托管 bean 中,您应该有 boolean renderIframeColumn 属性:

    private boolean renderIframeColumn;
    
    // getter and setter
    

    注意:在 Primefaces 3.5 中,p:lightBox 的加载是惰性的,因此 iframe 将在显示时立即加载。所以如果你可以升级到 PF 3.5。

    【讨论】:

    • 看起来不错。但是现在我得到一个异常,因为 Bean 名称:#{rollCommunityBean.renderPhoneColumn}": Target Unreachable, identifier 'rollCommunityBean' resolve to null 我更新了顶部的代码...
    • 你的bean根本不是托管bean!?添加@ManagedBean 和实际范围,例如@SessionScoped
    • 好的,现在我明白了。谢谢它几乎完美无缺。我现在的问题是,当我单击按钮时,我必须用 F5 刷新站点才能看到该列。我可以在不刷新的情况下显示它吗?
    • 我编辑了这个问题。我忘了把update 属性放在p:commandButton 中。
    • 嗯。添加了它,但没有任何改变...我的表:
    猜你喜欢
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    相关资源
    最近更新 更多