Primefaces:在p:dataTable中排除列以避免行选择

7
我遇到了一个问题,涉及 p:dataTable 和从单行选择中排除一列。
我的dataTable有4个列,前三个用于显示文件ID、文件名和上传日期。第4列中为每一行都有一个命令按钮,用于启动文件处理操作。 但也有行选择(通过事件触发AJAX操作),导航至文件详细信息页面。 现在,当我点击行上的任何位置(包括按钮)时,它都会将我导航到详细信息页面。
以下是我的当前代码:
<h:form>
    <p:dataTable id="billingFiles" value="#{billingFiles}"
        var="billingFile"
        rowKey="#{billingFile.billingFile.idBillingFile}"
        filteredValue="#{billingService.filteredBillingFileDataModels}"
        selectionMode="single" paginator="true" rows="10">

        <p:ajax event="rowSelect" listener="#{billingService.selectBillingFileRow}" />

        <p:column sortBy="#{billingFile.id}"
            filterBy="#{billingFile.id}" id="idFile"
            headerText="#{msg['billing.file.id']}"
            filterMatchMode="contains">
            <h:outputText value="#{billingFile.id}" />
        </p:column>

        <p:column sortBy="#{billingFile.uploadDate}"
            filterBy="#{billingFile.uploadDate}" id="uploadDate"
            headerText="#{msg['billing.file.upload_date']}"
            filterMatchMode="contains">
            <h:outputText value="#{billingFile.uploadDate}" />
        </p:column>

        <p:column sortBy="#{billingFile.fileName}"
            filterBy="#{billingFile.fileName}" id="fileName"
            headerText="#{msg['billing.file.file_name']}"
            filterMatchMode="contains">
            <h:outputText value="#{billingFile.fileName}" />
        </p:column>

        <p:column id="loadBillingFile">
            <p:commandButton id="loadBillingFileButton"
                rendered="#{billingFile.fileStatus.equals('UPLOADED')}"
                value="#{msg['billing.load_billing_file']}"
                action="#{billingService.loadBillingFile(billingFile.billingFile)}"
                update=":form" />
        </p:column>
    </p:dataTable>
</h:form>

这里有一种方法可以导航到文件详细信息页面:

public void selectBillingFileRow(SelectEvent event) {
    BillingFileDataModel billingFileDataModel = (BillingFileDataModel) event.getObject();
    if (billingFileDataModel != null) {
        selectedBillingFile = billingFileDAO.findBillingFileById(billingFileDataModel.getBillingFile().getIdBillingFile());
        FacesContext.getCurrentInstance().getExternalContext()
        .getRequestMap().put(JsfView.EVENT_KEY, "viewBillingFile");
    }
}

有没有办法从行选择中排除带按钮的列?我只需要它来开始处理文件,而不是将我导航到其他页面。

你正在处理什么文件,是数据库吗? - Roman C
它使用Spring Batch开始处理txt文件。 - Rozart
1
每当您单击行时,dataTable 上的 rowSelect Primefaces Ajax 事件会执行以下侦听器:"#{billingService.selectBillingFileRow}"。我会查看此方法的代码,以确定它是否正在重定向或转发页面。 - maple_shaft
您可以在我的问题细节中看到该方法。 - Rozart
1个回答

6
我找到了一个解决我的问题的部分方法。当发生点击事件onClick时,我阻止了rowSelect ajax操作的执行。
我在p:commandButton中添加了一行代码:
onclick="event.stopPropagation();"

我说它只能部分地工作,因为点击带有按钮的列,但不是按钮本身,仍会执行 rowSelect 操作。


另一个简单的选择是有选择性地获取SelectEvent的源(从getComponent()),并根据触发事件的组件类型有选择性地执行方法体的其余部分。 - kolossus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接