0

I have a datatable and polling in my Primefaces page. On Datatable on every row there is a commanButton. Because of polling, f:setPropertyActionListener does not works properly on button click. So I set ajax=false at button and trying to get datatable row "var" via a POST request. Is there a way to do that?

<p:poll interval="15" 
       listener="#{batchOperation.generateImportFTDBatchFileReport}" 
       update=":batchOperationsForm:growl :batchOperationsForm:batchfilestbl            
               :batchOperationsForm:dataimporttypeselectiontabview:importFTDbatchfilestbl
               :batchOperationsForm:dataimporttypeselectiontabview:importFTDerrorbatchfilestbl 
               :batchOperationsForm:dataimporttypeselectiontabview:importFTDStatusTxtId" 
       widgetVar="myPoll" autoStart="true"/> 

<p:dataTable id="batchfilestbl" var="batchFile"
                    value="#{batchOperation.batchFileModel}" paginator="true"
                    rows="#{batchOperation.batchFileModel.pageSize}"
                    paginatorPosition="bottom"
                    sortBy="#{batchOperation.createTime}"
                    sortOrder="descending"
                    emptyMessage="#{messages['common.datatable.emptymessage']}"
                    selectionMode="single" 
                    selection="#{batchOperation.selectedFile}">


   <p:column headerText="#{messages['content.batchoperations.datatable.header']}">

           <p:commandButton actionListener="#{batchOperation.createBatchFileForDownloadLatestRevision}"  
                        id="excelCreate" disabled="#{disableExcelVar}"
                        value="#{messages['content.batchoperations.createexcel.button.label']}"
                        ajax="false">
                        <f:setPropertyActionListener value="#{batchFile}"
                            target="#{batchOperation.selectedFile}" />
          </p:commandButton>
     </p:column>
</p:dataTable>

bahadir_g
  • 215
  • 2
  • 16

2 Answers2

0

If you want to send the whole model object as a parameter to a backing bean method, you can send it in using your var for the data table.

<p:dataTable var="myVar">
    <p:column>
        <p:commandButton actionListener="#{bean.method(myVar)}" />
    </p:column>
</p:dataTable>

Alternatively, if you are only interested in the row index, you can send just that using the rowIndexVar value for the data table.

<p:dataTable rowIndexVar="rowIndex">
    <p:column>
        <p:commandButton actionListener="#{bean.method(rowIndex)}" />
    </p:column>
</p:dataTable>

It looks like you are trying to do file download here. You may want to checkout this question.

Mitchell Brooks
  • 113
  • 2
  • 9
  • Thanks for suggestion, Mitchell. Unfortunately it did not work for me, maybe bacause of JSF/Primefaces version. I found an alternative solution working and posted below. – bahadir_g Oct 13 '17 at 12:20
0

Instead of using f:setPropertyActionListener, f:attribute solved my problem.

         <p:commandButton actionListener="#{batchOperation.createBatchFileForDownloadLatestRevision}"  
                            id="excelCreate" disabled="#{disableExcelVar}"
                            value="#{messages['content.batchoperations.createexcel.button.label']}"
                            ajax="false">
                <f:attribute name="bf" value="#{batchFile}" />
         </p:commandButton>

Method:

        public synchronized void createBatchFileForDownloadLatestRevision(ActionEvent event) throws Exception {

             selectedFile = (BatchFile) ((CommandButton) event.getSource()).getAttributes().get("bf");

             .
             .
        }
bahadir_g
  • 215
  • 2
  • 16