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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With