【问题标题】:Primefaces : <p:ajax inside of DataTable calls method several times after I update the dataTablePrimefaces:在我更新数据表后,DataTable 中的 <p:ajax 多次调用方法
【发布时间】:2013-02-06 15:24:34
【问题描述】:

问题在于“p:ajax event="rowDblselect" listener="#{companyBean.update()}" ...”,当我第一次双击时,调用了方法“update()”一次(完美!),但之后当我按下命令按钮“button1”并再次双击组件时,“update()”被调用了 2 次。当我再重复一次时,“update()”被调用了 3 次……………… 这很奇怪!我认为当我使用 commandButton 更新数据表时,ajax 事件会自行保持升级。我不知道(?)......谁能帮我解决它??

<h:panelGrid id="panel" columns="5">
  <p:commandButton id="button1"  value="Search" actionListener="#{                     
     companyBean.search()}" update="dataTable"/>          
</h:panelGrid>

<p:dataTable id="dataTable" var="companyTO" value="#{companyBean.companiesTO}"                      
  selection="#companyBean.selectedCompanyTO}" rowKey="#{companyTO}"                   
  emptyMessage="" selectionMode="single" >   

 <p:ajax event="rowDblselect" listener="#{companyBean.update()}" immediate="true"   
        process="@this" />

 <p:column >

     ...
<p:dataTable>

obs.:当我删除“update="dataTable" 时,“event="rowDblselect"" 工作正常,只调用一次方法。所以,问题出在更新上。

我在这里发现了同样的问题:https://stackoverflow.com/questions/11904556/updating-datatable-with-own-datamodel-calls-method-more-and-more

【问题讨论】:

  • 查看您生成的 html 代码。可能您不止调用该方法。你在companyBean.search() 方法中到底在做什么?

标签: jsf primefaces datatable


【解决方案1】:

尝试删除ajax 事件的immediate 属性并在commandbutton 中添加属性:

process="@this" partialSubmit="true" ajax="true"

类似这样的:

事件:

   <p:ajax event="rowDblselect" listener="#{companyBean.update()}" process="@this" partialSubmit="true" />

按钮:

 <p:commandButton id="button1"  value="Search" actionListener="#{                     
         companyBean.search()}" update="dataTable" process="@this" partialSubmit="true" ajax="true"/> 

【讨论】:

    猜你喜欢
    • 2017-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    相关资源
    最近更新 更多