Primefaces数据表 - 编辑&添加过滤器后,删除按钮不再有效

时间:2017-02-02 23:58:06

标签: jsf primefaces filter datatable

我有一个使用primefaces 5.1构建的数据表,在我添加过滤选项之前一直运行良好。我已经通过论坛了,我已经尝试了这些建议,但到目前为止还没有一个对我有用。这是我能找到的closest suggestion

我的数据表的每一行都有一个编辑和删除按钮。在我添加搜索过滤器代码之前,我可以单击编辑,预先填充的表单将显示正确的详细信息,也删除工作。一旦我将过滤代码添加到primefaces数据表,我点击编辑后会得到一个空白表格。删除按钮也会停止工作。

数据表:

    <p:growl id="messages" />
    <h2>Company</h2>

    <h:form id="form1">
        <p:dataTable value="#{companyController.companies}" var="company" id="companyTable" widgetVar="filteredcompanyTable"
                 emptyMessage="No records found with given criteria" filteredValue="#{companyController.filteredCompanies}">

            <p:column headerText="Name" sortBy="#{company.company_name}" filterBy="#{company.company_name}" filterMatchMode="contains">
                #{company.company_name}
            </p:column>
            <p:column headerText="Description">
                    #{company.company_description}
            </p:column>     
            <p:column headerText="Enabled">
                #{companyController.checkEnabled(company.enabled)}
            </p:column> 
            <p:column headerText="Updated" sortBy="#{company.date_modified}">
                #{companyController.formatDate(company.date_modified)}
            </p:column>
            <p:column headerText="Registered" sortBy="#{company.date_registered}">
                #{companyController.formatDate(company.date_registered)}
            </p:column>
            <p:column headerText="Options">
                <h:form>
                    <p:commandButton value="edit" action="#{companyController.setCompany(company)}" update=":form1:companyForm" 
                        oncomplete="PF('companyDialog').show(); " resetValues="true" />
                    <p:commandButton value="remove" action="#{companyController.remove(company)}" update=":form1:companyTable, :messages">
                        <p:confirm header="Confirmation" message="Are you sure?" icon="ui-icon-alert" />
                    </p:commandButton>
                </h:form>
            </p:column>
        </p:dataTable>

        <h:form>
            <p:commandButton value="add company" action="#{companyController.clear()}" update=":form1:companyForm" 
                oncomplete="PF('companyDialog').show()" resetValues="true" />
        </h:form>

        <p:dialog widgetVar="companyDialog" closeOnEscape="true" modal="true" header="company">
            <h:form id="companyForm">
                <p:focus />
                <p:panelGrid columns="2">
                    name:
                    <p:inputText value="#{companyController.company.company_name}" />
                    description:
                    <p:inputText value="#{companyController.company.company_description}" />
                    enabled:
                    <h:selectBooleanCheckbox value="#{companyController.company.enabled}" />

                </p:panelGrid>
                <p:commandButton value="save" action="#{companyController.save()}" update="companyForm, :form1:companyTable, :messages"
                    oncomplete="handleDialogSubmit(args, 'companyDialog'); PF('filteredcompanyTable').filter();" />
            </h:form>
        </p:dialog>
    </h:form>

    <h:form>
        <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" closeOnEscape="true">
            <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
            <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
        </p:confirmDialog>
    </h:form>


    <script type="text/javascript">
        function handleDialogSubmit(args, dialogName) {
            if(!args.validationFailed) {
                PF(dialogName).hide();
            }
        }
    </script>

以下是基础视图的代码:

public class CompanyController implements Serializable {

    private static final long serialVersionUID = 1L;

    @ManagedProperty("#{companyService}")
    private CompanyService companyService;

    private List<Company> companies;
    private List<Company> filteredCompanies;
    private Company company = new Company();

    @PostConstruct
    public void loadCompanies() {
        companies = companyService.fetchAll();
    }

    public void save() {
        companyService.save(company);
        clear();
        loadCompanies();
        FacesContext.getCurrentInstance().addMessage(null, 
                new FacesMessage(FacesMessage.SEVERITY_INFO, "Company saved!", null));
    }

    public void remove(Company company) {
        companyService.delete(company);
        loadCompanies();
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO, "Company de-registered!", null));
    }

    public void clear() {
        company = new Company();
    }

    public String formatDate(Date date) {
        DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
        return formatter.format(date);
    }

    public String checkEnabled(boolean status) {
        if (status==true) {return "YES";}
        return "NO";
    }

}

请帮助

0 个答案:

没有答案