想要在单击按钮后显示填充有数据的数据表 [英] Want to show a data table populated with data after a button click

查看:86
本文介绍了想要在单击按钮后显示填充有数据的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以这种方式编写代码,即如果单击按钮,则会出现一个填充了数据的数据表.在此之前,不应在视图中显示数据表.

I want to write a code in this way, that If I click on a button a data table appears populated with data. before that there should not be the data table in view.

<p:commandButton value="Go" styleClass="apply_button" actionListener="#{searchBean.getUserList}">
    <f:attribute name="trigram" value="#{searchBean.trigram}"/>
    <f:attribute name="firstName" value="#{searchBean.firstName}"/>
    <f:attribute name="lastName" value="#{searchBean.lastName}"/>
</p:commandButton>

此处的getUserList()方法返回应在数据表中填充的数据列表,并且可以正常工作.

here the method getUserList() returns a list of data that should be populated in the data table.and it works.

<p:dataTable value="#{searchBean.listUser}" var="user">
    <p:column headerText="Trigram">
        <h:outputText value="#{searchBean.trigram}"/>
    </p:column>
</p:dataTable>

单击按钮后,它会显示在数据表中,但是在单击按钮之前,数据表会出现,并带有空白字段.单击按钮后如何修改代码以显示数据表? 代码在<h:form>标记内.

It shows in the Data Table after I click on the button, But the Data Table appears before the button click with empty fields. How can I modify my codes to show make the Data Table appear after my button click? Codes are within the <h:form> Tag.

并且受管Bean searchBean@ViewScoped中.

And the Managed Bean searchBean is in @ViewScoped.

推荐答案

您可以初始化一个简单的getter/setter方法:

You can initialize a simple getter/setter :

private boolean visible = false; // getter/setter

public void getUserList(ActionEvent event)
{
    setVisible(true);

    // Your code
}

并像这样修改您的视图:

And modify your view like this :

<p:commandButton value="Go" styleClass="apply_button" actionListener="#{searchBean.getUserList}" update="table-wrapper">
    <f:attribute name="trigram" value="#{searchBean.trigram}"/>
    <f:attribute name="firstName" value="#{searchBean.firstName}"/>
    <f:attribute name="lastName" value="#{searchBean.lastName}"/>
</p:commandButton>

<h:panelGroup id="table-wrapper">
    <p:dataTable rendered="#{searchBean.visible}" value="#{searchBean.listUser}" var="user">
        <p:column headerText="Trigram">
            <h:outputText value="#{searchBean.trigram}"/>
        </p:column>
    </p:dataTable>
</h:panelGroup>

请注意按钮上的update属性,表上的h:panelGroup包装器和rendered属性.

Note the update attribute on button, h:panelGroup wrapper and rendered attribute on table.

这篇关于想要在单击按钮后显示填充有数据的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆