通过非ajax按钮发送请求获取Primefaces数据表行变量

时间:2017-10-11 11:46:00

标签: ajax jsf primefaces datatable

我的Primefaces页面中有一个数据表和轮询。在每一行的数据表上都有一个commanButton。由于轮询,f:setPropertyActionListener在按钮单击时无法正常工作。所以我在按钮处设置ajax = false并尝试通过POST请求获取数据表行“var”。有没有办法做到这一点?

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

2 个答案:

答案 0 :(得分:0)

如果要将整个模型对象作为参数发送到辅助bean方法,可以使用var将其发送到数据表中。

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

或者,如果您只对行索引感兴趣,则可以使用数据表的rowIndexVar值发送它。

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

看起来你正试图在这里进行文件下载。您可能想要结帐this问题。

答案 1 :(得分:0)

而不是使用f:setPropertyActionListener,f:属性解决了我的问题。

tagged_test_sentences = unigram_tagger.tag_sents([[token for token,tag in sent] for sent in test_sentences])
gold = [str(tag) for sentence in test_sentences for token,tag in sentence]
pred = [str(tag) for sentence in tagged_test_sentences for token,tag in sentence]
from sklearn import metrics
print(metrics.classification_report(gold, pred))

             precision    recall  f1-score   support

          .       1.00      1.00      1.00      2107
        ADJ       0.89      0.79      0.84      1341
        ADP       0.97      0.92      0.94      2621
        ADV       0.93      0.79      0.86       573
       CONJ       1.00      1.00      1.00       453
        DET       1.00      0.99      1.00      2456
       NOUN       0.96      0.76      0.85      6265
        NUM       0.99      0.85      0.92       379
       None       0.00      0.00      0.00         0
       PRON       1.00      0.96      0.98       502
        PRT       0.69      0.96      0.80       481
       VERB       0.96      0.83      0.89      3274
          X       0.10      0.17      0.12         6

avg / total       0.96      0.86      0.91     20458

方法:

That's all well and good, but how well does it perform on random sentences?