【问题标题】:Invoke <h:commandLink> action method using <f:ajax>使用 <f:ajax> 调用 <h:commandLink> 操作方法
【发布时间】:2011-07-20 14:14:18
【问题描述】:

我有以下代码:

<h:commandLink action="#{testBean.showSomething}">
    Do Stuff
</h:commandLink>

它可以满足我的需求(更改 testbean 的状态并重新加载将显示一组不同 div 的页面。因为它们的“渲染”属性) 现在我想使用 ajax 来完成这个,所以我这样做了:

<h:commandLink action="#{testBean.showSomething}">
    <f:ajax event="click" render=":content" />
    Do Stuff
</h:commandLink>

但是,这会导致 showSomething 方法甚至没有被调用。 恕我直言,我想做的事情相当简单,但我一辈子都不知道该怎么做。

【问题讨论】:

    标签: ajax jsf jsf-2


    【解决方案1】:

    您需要使用event="action" 而不是event="click"。你甚至可以完全省略它。这是&lt;f:ajax&gt; 嵌套在UICommand 组件中时正在侦听的默认事件。

    <h:commandLink action="#{testBean.showSomething}">
        <f:ajax render=":content" />
        Do Stuff
    </h:commandLink>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-29
      • 2015-05-08
      • 2012-04-13
      • 2012-12-24
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多