p:commandButton不会触发操作

时间:2011-11-25 13:16:33

标签: jsf primefaces

问题在于:actionlistener不想被解雇

@ManagedBean(name="hotelsController")
@SessionScoped
   public class HotelsController implements Serializable {
      public void requestHotelAvail(ActionEvent event) {
         request = new Request(df.format(arrivalDate), df.format(departureDate));
      }
   }

和xhtml

<h:panelgroup id="rooms"/>
<h:form  id="hotelSearch">
            <p:commandButton actionListener="#{hotelsController.requestHotelAvail}" value="submit" update="rooms" />
</h:form>

我已尝试将所有可以搜索的内容更改为@managedbean@componentimport设置为import javax.faces.event.ActionEvent;

但它仍然没有发射任何东西。

表单位于p:accordion,与h:commandbutton一起使用时效果很好

编辑:抱歉误导。单击后会更新房间,但不会触发actionListener。所以房间不会得到任何新数据。 requestHotelAvail中的重要代码需要在更新房间之前触发,而不是。

EDIT2 PrimeFaces 2.2.1 - 我已经阅读了整本手册,但是我没有解释这一点,因为我已经完成了所有的陈述

我尝试使用action代替actionListener而不使用ActionEvent,但它从未做过任何事情。使用<h:commandbutton action="#{hotelscontroller.requestHotelAvail}"/>效果很好,但我希望ajax引擎只刷新rooms panelgroup

更新:现在可以了。表格不能在<p:accordion>但是为什么以及如何在那里启用它?现在,我将在没有它的情况下工作。

2 个答案:

答案 0 :(得分:3)

我怀疑h:commandLink的不同行为来自ajax / non-ajax处理。

默认情况下 - 如果你不使用f:ajax -h:commandLink是非ajax并且整个页面都被重新呈现。 Primefaces p:commandLink正在使用ajax,您将房间指定为要更新的组件。在你的情况下,房间是外面的形式,所以它应该被称为:房间(介意冒号),而不仅仅是房间。

更新:你用h:commandLink试过ajax吗?它将是:

<h:commandButton action="#{hotelscontroller.requestHotelAvail}" value="submit">
  <f:ajax render=":rooms"/>
</h:commandButton>

我也不熟悉primefaces,但也许你可以尝试用额外的process="@this"明确指出要处理的组件 - 尽管我认为这是默认的基本库。

答案 1 :(得分:0)

您尝试检查响应:

打开 Chrome或Firefox - &gt;检查元素 - &gt;网络并按照ajax调用。

enter image description here

相关问题