Want to show a data table populated with data after a button click

后端 未结 1 888
广开言路
广开言路 2021-01-24 18:21

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.



        
相关标签:
1条回答
  • 2021-01-24 18:41

    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>
    

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

    0 讨论(0)
提交回复
热议问题