【问题标题】:p:ajax not working with p:commandButtonp:ajax 不能与 p:commandButton 一起使用
【发布时间】:2013-05-21 08:26:30
【问题描述】:

我尝试这样做,但我从来没有成功过;为什么不支持 ajax??

<p:commandButton value="MAJ" rendered="#{LigneXL.resultat eq 'Pas de FMD'}" onclick="confirmation.show()"  >
    <f:setPropertyActionListener target="#{parserXls.selectitem}" value="#{LigneXL}" />                  
    <p:ajax event="click" listener="#{parserXls.listenercomposant()}"/>             
</p:commandButton> 

Listener 永远不会被执行 为什么!!! 我正在尝试根据selectitem获取另一个对象

public void listenercomposant(){
    composantitem=ChercherComposant(selcetitem.getRefcomposant(), selcetitem.getReffabricant());
}

【问题讨论】:

  • 我希望 selcetitem 在你的真实代码中拼写正确

标签: ajax primefaces


【解决方案1】:

p:commandButton 本身已经是 ajax enabled。所以里面不需要p:ajax,你可以使用

  <p:commandButton value="TestButton" actionListener="#{bean.saveSomething}" id="id"    
  update="panel" />

如您所见,p:commandButton 已经有了 actionListener,所以就使用它吧。

【讨论】:

  • 是的,我尝试使用它,但是当我使用时,选择项没有更新,因为 set 属性是在操作列表器之后执行的
  • 当我使用 actionListner 时,selectitem 为空
  • 你能告诉我你到底想做什么吗?你正在处理什么样的场景?
  • 我正在处理数据表,每个 ligne 都有按钮。当我单击按钮时,我会更改此 ligne 的某些属性,这就是我使用 setpropertyActionListener 的原因。但我还需要根据这个选择项
  • 请接受作为答案。
【解决方案2】:

这是我使用动作而不是监听器的解决方案

  <p:commandButton value="MAJ" rendered="#{LigneXL.resultat eq 'Pas de FMD'}" onclick="confirmation.show()" action="#{parserXls.listenercomposant()}" >
    <f:setPropertyActionListener target="#{parserXls.selcetitem}" value="#{LigneXL}" />                                            
    </p:commandButton> 

【讨论】:

  • 这不使用ajax。
  • @GregD:确实如此…… ajax 内置在这个组件中
  • @Kukeltje 确实如此。一年多前我发布此评论时并没有意识到这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-10
  • 2018-02-21
  • 1970-01-01
  • 2017-01-09
  • 2017-04-14
  • 2016-09-16
相关资源
最近更新 更多