jsf h:dataTable - 删除行后不刷新

时间:2017-06-21 09:23:17

标签: jsf

Hello Guys我需要你的帮助照常

Jsf h:dataTable - 删除行后不刷新。

直到我必须重新启动程序。

我该怎么办才能解决这个问题?

谢谢约翰。

ManagedBean

public List<Customer> getCustomerList() {

    if (customerList == null) {

        customerList = new ArrayList<Customer>(bookstoreManager.getAllCustomers());

        for (Customer cus : customerList) {
            System.out.println("Hello" + cus.getFirstName() + "......." + cus.getLastName());
        }
   }

    return customerList;
}

Business Logik

public List<Customer> getAllCustomers() {

    TypedQuery<Customer> query = em.createQuery("Select c from Customer c", Customer.class);

    return query.getResultList();
}

XHTML代码

<ui:define name="content">
    <h:body>
        <h:outputStylesheet name="css/style.css" />

        <h:form id="form">
            <h:dataTable var="cus" cellpadding="5" cellspacing="5" border="1"
                width="400" styleClass="customerList"
                value="#{customerBean.getCustomerList()}">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="#{texts.firstName}" />
                    </f:facet>
                    <h:outputText value="#{cus.firstName}" />
                </h:column>

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="#{ texts.lastName}" />
                    </f:facet>

                    <h:outputText value="#{cus.lastName}" />
                </h:column>

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="#{texts.address}" />
                    </f:facet>
                    <h:outputText value="#{cus.address}" />
                </h:column>

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="#{texts.creditCard}" />
                    </f:facet>
                    <h:outputText value="#{cus.creditCard}" />
                </h:column>

                <h:column>
                    <h:commandLink action="#{customerBean.selectCustomer(cus)}"
                        value="Edit" />
                </h:column>


                <h:column headerText="Delete">
                    <h:commandLink value="#{texts.delete}"
                        action="#{customerBean.deleteCustomer(cus)}" />
                </h:column>
            </h:dataTable>
        </h:form>
    </h:body>
</ui:define>

0 个答案:

没有答案