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.

Rozart
  • 1,668
  • 14
  • 27
  • What a file do you processing, is it a db? – Roman C Feb 14 '13 at 16:21
  • It starts processing txt file with Spring Batch. – Rozart Feb 14 '13 at 16:23
  • 1
    You have a rowSelect Primefaces Ajax event on the dataTable that executes the following listener whenever you click a row: `"#{billingService.selectBillingFileRow}"` I would look in the code for this method to see if it is redirecting or forwarding the page. – maple_shaft Feb 14 '13 at 16:48
  • You can see the method in the details of my question. – Rozart Feb 14 '13 at 17:08

1 Answers1

6

I found a partial solution to my problem. I prevented rowSelect ajax action from executing, when onClick event occurs.

I added this line to p:commandButton:

onclick="event.stopPropagation();"

I said it works partially, because click on column with button, but not on the button itself, still executes rowSelect action.

Rozart
  • 1,668
  • 14
  • 27
  • Another crude option will be to selectively get the source of the `SelectEvent`(from `getComponent()`) and selectively execute the rest of the method body based on the type of component that triggers the event – kolossus Feb 15 '13 at 14:27