Primefaces: Exclude column from row selection in p:dataTable

試著忘記壹切 提交于 2019-12-07 02:49:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14879193/primefaces-exclude-column-from-row-selection-in-pdatatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!