p:commandButton在使用过滤器时不在p:dataTable中工作

时间:2015-07-03 03:13:47

标签: jsf primefaces

我正在使用JSF,Primefaces 5.2和GlassFish 4.1。

我已经设置了一个简单的项目来测试和复制我的大问题,发现它在测试项目中是可重复的。

我有一个简单的页面,其中包含一个简单的对象列表。我正在使用<p:dataTable>并使用全局搜索功能和分页。

表格代码

<ui:define name="content">
    <h:form id="carsForm" >
        <p:dataTable id="singleDT" var="c" value="#{testFlow.cars}" widgetVar="carsTable" rows="10" paginator="true"
                     paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15" emptyMessage="No cars found with the given criteria" reflow="true"
                     filteredValue="#{testFlow.filteredCars}">

            <f:facet name="header">
                <p:outputPanel class="fright">
                    <h:outputText value="Search all fields: " />
                    <p:inputText id="globalFilter" onkeyup="PF('carsTable').filter()" style="width:200px" placeholder="Enter keyword" />
                </p:outputPanel>
                <p:outputPanel class="Fleft">
                    <p:commandButton value="New Car" action="addCar" />
                </p:outputPanel>
                <div class="EmptyBox5"></div>
            </f:facet>

            <p:column filterBy="#{c.id}" headerText="ID" sortBy="#{c.id}" >
                <h:outputText value="#{c.id}"/>
            </p:column>

            <p:column filterBy="#{c.m}" headerText="Model Year" sortBy="#{c.modelYear}" >
                <h:outputText value="#{c.modelYear}"/>
            </p:column>

            <p:column filterBy="#{c.make}" headerText="Make" sortBy="#{c.make}" >
                <h:outputText value="#{c.make}"/>
            </p:column>

            <p:column filterBy="#{c.model}" headerText="Model" sortBy="#{c.model}" >
                <h:outputText value="#{c.model}"/>
            </p:column>

            <p:column filterBy="#{c.color}" headerText="Color" sortBy="#{c.color}" >
                <h:outputText value="#{c.color}"/>
            </p:column>

            <p:column style="width: 200px; text-align: center">
                <p:commandButton actionListener="#{testFlow.removeCar(c)}" value="Delete" update="singleDT messages" ajax="true" >
                    <p:confirm header="Confirmation" message="Are you sure?" icon="ui-icon-alert" />
                </p:commandButton>
            </p:column>
        </p:dataTable>

        <div class="EmptyBox5"></div>
        <p:panel>
            <p:commandButton action="returnFromTestFlow" value="Exit the Flow" />
        </p:panel>
    </h:form>

    <p:messages id="messages" autoUpdate="true" closable="true" />

    <p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
        <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>
</ui:define>

我的控制器有一个简单的方法来删除对象。

方式

public String removeCar(Inventory c) {
    String redirectTo = "/testFlow/testFlow";

    try {
        this.cars.remove(c);
        iFacade.remove(c);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

    return redirectTo;
}

当我删除所有过滤和排序时,在我单击是并删除该行后调用该方法。虽然过滤和排序已经到位,但是整个表只是显示为空,但是没有调用任何方法。没有出现错误,并且在使用调试器时,它永远不会遇到相关方法中的断点。

非常感谢任何帮助或指示。

2 个答案:

答案 0 :(得分:0)

遇到了同样的问题,@djst 解决方案对我不起作用,但我最终通过使用 Omnifaces 表单 (o:form) 而不是标准的 h:form 解决了这个问题。虽然不知道为什么,但可能值得一试。

答案 1 :(得分:-1)

当您使用过滤时,primefaces会创建一个列表并在结果中显示它,当您从主列表中删除项目时,它与显示列表无关,这可能会导致发生的问题给你。

相关问题