7

I've got problem with p:dataTable and excluding a column from single row selection.

I have 4 columns in my dataTable. First 3 are needed to display fileId, fileName and uploadDate. In 4th column there is a command button for each row that start action of file processing. But also there is row selection (with ajax action on event) that navigates to file details page. Now, when I click on the anywhere on the row (including the button) it navigates me to details page.

There's my current code:

<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>

And there is the method that navigates to file details page:

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");
    }
}

Is there any way to exclude column with the button from row selection? I need it only to start processing the file, without navigating me to other page.

4

1 回答 1

6

我找到了解决问题的部分方法。当事件发生时,我阻止了rowSelectajax 动作的执行。onClick

我将此行添加到p:commandButton

onclick="event.stopPropagation();"

我说它部分工作,因为单击带有按钮的列,而不是按钮本身,仍然执行rowSelect操作。

于 2013-02-15T11:34:33.047 回答